fgrep files and insert characters before & after the output

I’m preparing a Unix shell script to scan backup log and to check for failure code.

If the directory backup is finished with failure, then the script must be able to pick-up the failed directory and write to an include file for re-submit later.

The backup log should have showing following result:

Backup processing of '/fscm/ldata/91/*' finished without failure.
Backup processing of '/fscm/ldata/92/*' finished without failure.
Backup processing of '/fscm/ldata/93/*' finished without failure.
Backup processing of '/fscm/ldata/94/*' finished without failure.
Backup processing of '/fscm/ldata/95/*' finished without failure.

What if some directories were failed to backup?

Backup processing of '/fscm/ldata/97/*' finished with failure.
Backup processing of '/fscm/ldata/98/*' finished with failure.

I need to extract the directory name and insert double quote before and after the directory name to prepare the include file.

The command is (type in single line)

grep “finished with failure” | cut -f2 -d “‘” | sed ‘s/^/”/’ | sed ‘s/$/”/g’

The code will return result as

"/fscm/ldata/95/*"
"/fscm/ldata/96/*"

This script was written and tested on AIX 5.1 and ksh Shell. You should be able to execute in any Unix and shell environment.

You’re welcome to comment.

Popularity: 18% [?]

This entry was posted in Shell Script and tagged , . Bookmark the permalink.

One Response to fgrep files and insert characters before & after the output

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>