Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 11-05-2004, 06:27 PM   #1
Registered: Sep 2004
Location: NH
Distribution: FC6, FC1-4, RH9, Gentoo 2006.0/1, Slackware 10.1/2,11, Vector SOHO 5.0.1
Posts: 237

Rep: Reputation: 30
Deleting a line with gawk/awk

I was wondering how I would delete a line using gawk/awk.

have this command to find the line I want to delete:
 gawk '/\/dev\/sda1/ { print }' test1
I know I shouldn't be printing the line, but is ther something I can put in the braces to remove the line from the text file. I am trying to use this in a script that a non-linux user can use to finalize installaions for me while I move on to the next machine.

Thanks in advance.
Old 11-05-2004, 07:21 PM   #2
Senior Member
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,284

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
Why do you need to use gawk? I just do a grep -v on the regular expression and redirect the ouput wherever you want it to go.
Old 11-05-2004, 07:30 PM   #3
Registered: Sep 2004
Location: NH
Distribution: FC6, FC1-4, RH9, Gentoo 2006.0/1, Slackware 10.1/2,11, Vector SOHO 5.0.1
Posts: 237

Original Poster
Rep: Reputation: 30
Oh, wow that is much easier. Thanks.
(Oh if anyone saw the post that was here for about 1 minute, taht was because I didn't read the right "-v" )

Last edited by caps_phisto; 11-05-2004 at 07:33 PM.
Old 11-06-2004, 01:13 PM   #4
Registered: Aug 2004
Distribution: debian, SuSE
Posts: 365

Rep: Reputation: 35
sed would work too

sed '/searchpattern/d' filename >newfile
Old 11-06-2004, 02:31 PM   #5
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
And just so awk doesn't fall aside ...

awk '!/hda1/ {print}' /etc/fstab

awk is absolutely awksome! :)



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
Awk command-line arguments lowpro2k3 Programming 1 03-28-2005 09:09 PM
problem deleting file using solaris command line. szehanz Solaris / OpenSolaris 2 03-22-2005 07:52 PM
deleting characters at the beginning of a line poobeany Programming 6 09-23-2003 05:17 PM
deleting a file via comman line PionexUser Linux - General 2 09-17-2003 12:27 AM
awk/gawk handling of "delete" ? realos Programming 1 06-26-2003 09:45 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:38 AM.

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