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

awk or sed command-line routine to solve this situation? 1

Status
Not open for further replies.

ranadhir

Programmer
Nov 4, 2003
54
IN
We hava data file which has entries in this format:
sap/base/parser/agent/wholeworld.cpp

These have to be converted into :
wholeworld.cpp|sap/base/parser/agent/
ie <filename>|<path>

This has to be done via command-line.
and we cannot do a hard-coded awk -F/ print{$NF "|" $0"/"$1.... etc.},as the path-name length will be different all over.

How can this be done ?
Even a sed-based command-line solution will suffice(leaner the better!!!!)

Any help would be appreciated
 
awk 'BEGIN{OFS=FS="/"}{base=$NF;$NF="";print base "|" $0}'

HTH,

p5wizard
 
Another way in ksh-like shell:
while read f
do echo $(basename $f)'|'$(dirname $f)'/'
done < /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top