|
|
Shell SCript help....
|
|
|
|
Forum Regular
Join Date: Nov 2000
Location: Boston Area,ma
Status:
Offline
|
|
I have a simple shell script that loops through a text file.
There is one value on each line I use to delete a specific folder.
The part I'm missing how to do it remove that line from the text file.
So basically....loop through the text file and remove the line after using it to be a variable of a command.
cheers
Robert
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status:
Offline
|
|
Originally Posted by BostonMACOSX
I have a simple shell script that loops through a text file.
There is one value on each line I use to delete a specific folder.
The part I'm missing how to do it remove that line from the text file.
So basically....loop through the text file and remove the line after using it to be a variable of a command.
Something like this should do:
Code:
while read cur_line
do
folder=`echo $cur_line | awk '{print $2}'`
echo Currently deleting $folder...
sed "/$cur_line/d" yourfile> tempfile
mv tempfile yourfile
done < yourfile
I don't know what you're using to find the folder-to-be-deleted's name on the current line, but I set it up to be the second field in the current line using that awk statement in the while loop. If you need help, just post again and I'll clarify...
Basically, use sed to delete the line from the file, then output it to a temp file, then move that temp file back to the name of your file.
|
"In Nomine Patris, Et Fili, Et Spiritus Sancti"
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status:
Offline
|
|
To be a bit more abstract, the answer is that there is no really simple way to delete just one line from a file. You have to copy all the other lines into a new file, and then replace the old file with the new one.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|