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

print the last field of a record using awk

Status
Not open for further replies.

Lesleyb

Technical User
Nov 19, 2003
1
US
Hi,

My file looks something like the following

/data/udb/sync/exp/hrzsync.exp.1
/data/udb/sync/exp/hrzsync.exp.2
/data/udb/sync/exp/hrzsync.exp.3
etc............

I need to print the last field (FS="/") ie just the file names, removing the preceeding full path so that my output is

hrzsync.exp.1
hrzsync.exp.2
hrzsync.exp.3

Running this within a script the exact number of entries in the directory string will vary so I can't simply use $5 with FS="/"

Can anyone help

Thanks
Lesley
 
You could use

awk -F/ '{print $NF}' file1

Maybe 'man basename' will help too.
 
Another way is to use sed:
Code:
sed -e 's!.*/!!' files.lst

Hope This Help
PH.
 
Not awk, but ksh solution :-

while read filens
do
print `basename $filens`
done < yourfile

Dickie Bird (:)-)))
 
Yet another way, with ksh:
Code:
while read path
do echo ${path##*/}
done<files.lst

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top