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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Script to Remove lines from a file

Reply to Message Icon

Name: Justin
Date: July 8, 2003 at 08:12:27 Pacific
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.



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: July 8, 2003 at 09:31:29 Pacific
Reply:

grep -v BOUNDARY infile > outfile


0

Response Number 2
Name: Peter
Date: July 8, 2003 at 10:58:10 Pacific
Reply:

sed '/BOUNDARY/d' infile > outfile


0

Response Number 3
Name: Justin
Date: August 1, 2003 at 10:37:50 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Trouble with getting all ... find command and tar file...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Script to Remove lines from a file

Script to delete lines from a file www.computing.net/answers/unix/script-to-delete-lines-from-a-file/7408.html

Get the first line from a file www.computing.net/answers/unix/get-the-first-line-from-a-file/7981.html

Script to insert lines in a file www.computing.net/answers/unix/script-to-insert-lines-in-a-file/4992.html