LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 05-23-2003, 07:26 AM   #1
netkepala
Member
 
Registered: Sep 2002
Distribution: Red Hat
Posts: 68

Rep: Reputation: 15
Question How to remove line of text from file


Hi All,

I wonder if there's a linux command which will be able to remove
a whole line of text from a file given a certain phrase

I know I can do a

cat filename|grep phrase

but that will only display the whole line of text.

How do I erase that whole line of text and save the changes
back to that file ?

Thank you
 
Old 05-23-2003, 07:36 AM   #2
jharris
Senior Member
 
Registered: May 2001
Location: Bristol, UK
Distribution: Slackware, Fedora, RHES
Posts: 2,243

Rep: Reputation: 46
You could use
Code:
grep -v phrase inputFile > outputFile
which would create a new file called outputFile that contains all lines that don't contrin "phrase". You might want to consider looking into sed and awk though for a more elegant solution.

cheers

Jamie...
 
Old 05-23-2003, 12:49 PM   #3
netkepala
Member
 
Registered: Sep 2002
Distribution: Red Hat
Posts: 68

Original Poster
Rep: Reputation: 15
thanks, i will try it out
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting 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


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ text file line by line/each line to string/array Dimitris Programming 15 03-11-2008 09:22 AM
remove text from file with script paul_mat Linux - Software 3 11-17-2005 01:21 PM
Remove odd lines from a text file Mr. Gone Programming 2 09-19-2005 12:16 PM
View Line In Text File DaveyB Programming 1 11-03-2004 01:02 PM
PERL:: trying to remove last line of file ocularbob Programming 16 09-01-2003 02:07 PM


All times are GMT -5. The time now is 10:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration