[Novalug] Unix script help request
Kevin Starkey
kevin.linuxfan at gmail.com
Sat Feb 21 08:32:38 EST 2009
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.
More information about the Novalug
mailing list