[Novalug] Unix script help request

Garrett Nievin gnievin@comcast.net
Sat Feb 21 09:51:32 EST 2009


Oops.  Change "done" to "fi".

Hard to concentrate on Unix on a day like today with the nice flying weather.
I'm off to the airport now.

Cheers,
Garrett

On Sat, 21 Feb 2009 09:04:56 -0500
Garrett Nievin <gnievin@comcast.net> wrote:

> One possible solution:
> 
> If you do a grep with the "-q" option (quiet), it will just set the
> exit code to 0 if the text was found and 1 if it was not.  You can
> check the exit code using the shell variable ?.  The question mark
> character is the name of the variable.
> 
> Here's some nice structured mainframe-y code:
> 
> # see if $loopfile contains the magic string, and do something accordingly
> grep -q '<TRANS_CDE>RSCF' $loopfile
> if [ $? -eq 0 ] ; then
> 	echo "string was found"
> else
> 	echo "string was not found"
> done
> 
> 
> 
> On Sat, 21 Feb 2009 08:32:38 -0500
> Kevin Starkey <kevin.linuxfan@gmail.com> wrote:
> 
> > Hi all,
> > 
> > My Linux experience (meager as it is) is finally starting to be 
> > applicable at my job (mainframe programmer). We just started using a 
> > Unix file server on the mainframe and occasionally we run into an issue 
> > to solve and I volunteered to tackle this one. The issue is, I might 
> > have 0, 1, or > 1 files in a directory with the same name pattern of 
> > "EBPV************.out.xml" and one of these files might be the one I'm 
> > looking for, or it might not. I need to identify a particular string 
> > inside of the file, and if it matches, then I want to add an 'S' to the 
> > start of the name (SEBPV....).
> > 
> > Below is the start of a script that I hope is close to what I need, but 
> > I need to add "grep" and a conditional statement where I only do the 
> > renaming if the grep finds what I'm looking for, but I'm not sure how to 
> > code that part (this is my first script).
> > 
> > ---------------------------------------------------------------------------------------------------
> > #!/bin/bash
> > 
> > # Change to directory
> > cd /proj/preed/output
> > 
> > #Get all needed files in current directory
> > originalFiles=$(ls EBPV*.out.xml)
> > 
> > # Loop through all files and do your changes
> > for loopFile in $originalFiles
> > do
> > # Create your new filename including the extension
> > mv $loopFile S$loopFile
> > done
> > ---------------------------------------------------------------------------------------------------
> > 
> > I need to somehow add:
> > 
> > grep $loopfile "<TRANS_CDE>RSCF"
> > 
> > and only if it's found then I want to do the "mv ...." (renaming).
> > 
> > Any help would be greatly appreciated.
> > 
> > Thanks,
> > Kevin.
> > 
> > _______________________________________________
> > Novalug mailing list
> > Novalug@calypso.tux.org
> > http://calypso.tux.org/cgi-bin/mailman/listinfo/novalug
> > 
> 
> 
> 
> _______________________________________________
> Novalug mailing list
> Novalug@calypso.tux.org
> http://calypso.tux.org/cgi-bin/mailman/listinfo/novalug
> 






More information about the Novalug mailing list