Computing.Net > Forums > Unix > Script to Remove lines from a file

Script to Remove lines from a file

Reply to Message Icon

Original Message
Name: Justin
Date: July 8, 2003 at 08:12:27 Pacific
Subject: Script to Remove lines from a file
OS: Solaris 8
CPU/Ram: SPARC 64
Comment:

I was wondering if you could help me with a script to remove ALL the lines in a file that contain the word "BOUNDARY". I have the script like this so far, but It will only remove the first occurance of BOUNDRY, not all of them like I want.


#!/bin/bash
line=$(grep -n "BOUNDARY" foo.c | cut -d: -f1 | sed '1q' )
sed ${line}d foo.c > foo_new.c


thanks for your help.


Report Offensive Message For Removal

Response Number 1
Name: David Perry
Date: July 8, 2003 at 09:31:29 Pacific
Subject: Script to Remove lines from a file
Reply: (edit)

grep -v BOUNDARY infile > outfile


Report Offensive Follow Up For Removal

Response Number 2
Name: Peter
Date: July 8, 2003 at 10:58:10 Pacific
Subject: Script to Remove lines from a file
Reply: (edit)

sed '/BOUNDARY/d' infile > outfile


Report Offensive Follow Up For Removal

Response Number 3
Name: Justin
Date: August 1, 2003 at 10:37:50 Pacific
Subject: Script to Remove lines from a file
Reply: (edit)

Thanks sed '/BOUNDARY/d' infile > outfile did the trick.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Script to Remove lines from a file

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software