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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Awk command 1

Status
Not open for further replies.

nwo4life

Technical User
May 16, 2002
23
0
0
US
I have a script that looks like this I need it to drop the
directory and the gz of the filename. All I want is (test.test2.tar) for f. With this it gives me test.test2.tar.gz. Any help appreciated. Thanks

Example filename
/tmp/backup/test.test2.tar.gz

for i in `ls $dir/*.tar.gz`
do
echo $i
f=`exho $i | awk -F/ '{print $3}'`
gunzip $i
tar xvf $f.tar
gzip $f.tar
Done
 
Try

f=`echo $i | awk -F/ '{sub(/\.gz$/,"",$3);print $3}'`

CaKiwi
 
basename dors all work

for i in `ls $dir/*.tar.gz`
do
echo $i
f=`basename $i .gz`
gunzip $i
tar xvf $f.tar
gzip $f.tar
done

Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top