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!

Split text on /

Status
Not open for further replies.

alan147

Technical User
Nov 15, 2002
128
GB
Good afternoon

I have a file with rows of text in of the form

xxx/aaaaaaaaa
xxx/bbbbbbbbb

xxx is a directory name and aaaaaaaa is a file. Generally xxx is three characters long but could be longer. I need to be able to extract the directory name and the file name as seperate variables.

Does anyone know how to do this?

Thanks

Alan
 
This will do it ..
Code:
for line in `cat file`
do
dir=`dirname $line`
file=`basename $line`
echo "dir=$dir file=$file"
done
Greg.
 
Another way:
IFS="/$IFS" while read dir file
do echo "dir='$dir', file='$file'"
done </path/to/inputfile

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

Part and Inventory Search

Sponsor

Back
Top