Home » Infrastructure » Unix » Read contents of text file using unix shell scripts
Read contents of text file using unix shell scripts [message #172168] Mon, 15 May 2006 06:08 Go to next message
arunvijay
Messages: 2
Registered: May 2006
Junior Member
Hi all,

I have a text file which contains the name of the files that has to deleted. My requirement is that, i should read the contents of the text file,line by line,inside the shell script and delete the files mentioned in the text file.

can anyone help me out in solving this????


thnx in advance
Re: Read contents of text file using unix shell scripts [message #172171 is a reply to message #172168] Mon, 15 May 2006 06:20 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
oracle@mutation#cat listoffiles.txt
ross_count.lst
rk1.lst
result.lst
report_indexes.lst
reb_store.lst
reb.lst


oracle@mutation#cat delete_script
#!/usr/bin/bash
DELDIR=/home/oracle/scr/ora/deleteme
cat listoffiles.txt | while read filename
do
echo deleting file $DELDIR/$filename
rm $DELDIR/$filename
done

oracle@mutation#delete_script
deleting file /home/oracle/scr/ora/deleteme/ross_count.lst
deleting file /home/oracle/scr/ora/deleteme/rk1.lst
deleting file /home/oracle/scr/ora/deleteme/result.lst
deleting file /home/oracle/scr/ora/deleteme/report_indexes.lst
deleting file /home/oracle/scr/ora/deleteme/reb_store.lst
deleting file /home/oracle/scr/ora/deleteme/reb.lst
Re: Read contents of text file using unix shell scripts [message #172197 is a reply to message #172171] Mon, 15 May 2006 08:17 Go to previous message
arunvijay
Messages: 2
Registered: May 2006
Junior Member
thnx a lot mahesh...ur code perfectly answered by requirement
Previous Topic: How can I add the 10 th parameter to the shell script
Next Topic: error in sysconfitab file hp tru64
Goto Forum:
  


Current Time: Tue Apr 23 17:14:41 CDT 2024