reading path from a text file using bash script
hi all
I have a text file which consist file names with complete path. I want a script which takeout path of file one by one and store path in a variable and file name in other variable. i am giving you some part of this text file: /root/Documents/ListOfnts.ods /root/Documents/NewCmpnDet.xls /root/Documents/ComTstChkLst.ods /root/Documents/compstat.ods /root/Documents/PDF BOOKS/handbook.pdf /root/Documents/200804A0/04042008944.jpg /root/Documents/printer/steps.txt /root/Documents/AC97/bus.h with the help of script I want output like this PATH=/root/Documents/ FILE=ListOfnts.ods Thanks MKSC |
Hi,
You could use the basename and dirname commands to split directories from filenames. The first one (basename) will strip the dir part, the other one does the opposite: Quote:
Code:
$ for THIS in `cat infile` |
You can either use the dirname and basename commands into a loop which reads the file line by line, or use the following parameter substitution:
Code:
P=${line%/*} An aside note: don't use PATH as name of a variable in your script, since it is a reserved word for the environment variable PATH. If you change its value inside your script, most likely you will get "Command not found" errors for subsequent statements. |
All times are GMT -5. The time now is 08:01 PM. |