Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

shell script help - using find

Status
Not open for further replies.

netrookie

Technical User
Jul 6, 2003
29
US
I have the following shell script:

#!/bin/bash
find /db1/sgl/backup/ -name "*sgl*" -mtime +20 -print | cut -c21-28 | while read RECORD
do
echo "ls -ltr *$RECORD*" >> listfiles.sh
done


The output file would look like this:
ls -ltr *sgl_p814*

But there are instances where the filename has thousands place, example sgl_p1000

Sample of files:
/db1/sgl/backup/sgl.sgl_p667.20100522221001.gz
/db1/sgl/backup/sgl.sgl_p669.20100522221001.gz

/db1/sgl/backup/sgl.sgl_p1000.20100522221001.gz

In other words, I would need to use cut -c21-28
cut -c21-29 to get what I need.

I would like to extract the values between the dots ".sgl_pXXX[X]."

Is there a better way to write this? Thanks!


 
perhaps this? [tt]cut -d'.' -f2[/tt]

Have a look at the [tt]man cut[/tt] manual page.

HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top