Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > Shell SCript help....

Shell SCript help....
Thread Tools
BostonMACOSX
Forum Regular
Join Date: Nov 2000
Location: Boston Area,ma
Status: Offline
Reply With Quote
May 24, 2005, 02:23 PM
 
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
OSX ...Plastic surgery for unix
Boston Area Consulting
http://rjhcc.dyndns.biz
http://bostonmacosx.dyndns.org
     
[APi]TheMan
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status: Offline
Reply With Quote
May 25, 2005, 03:58 AM
 
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"

     
wataru
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status: Offline
Reply With Quote
May 25, 2005, 09:48 AM
 
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.
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 08:34 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,