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!
#!/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!