LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux > Linux - General
User Name
Password
Linux - General This 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
 
Thread Tools
Old 11-05-2004, 07:27 PM   #1
caps_phisto
Member
 
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
Thanked: 0
Deleting a line with gawk/awk


[Log in to get rid of this advertisement]
I was wondering how I would delete a line using gawk/awk.

have this command to find the line I want to delete:
Code:
 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.
caps_phisto is offline     Reply With Quote
Old 11-05-2004, 08:21 PM   #2
btmiller
Senior Member
 
Registered: May 2004
Distribution: At home: Kubuntu, Slackware, *BSD, Solaris. At work: Red Hat, CentOS, Debian, Fedora, Irix, HPUX
Posts: 3,341
Thanked: 8
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.
btmiller is offline     Reply With Quote
Old 11-05-2004, 08:30 PM   #3
caps_phisto
Member
 
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
Thanked: 0

Original Poster
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 08:33 PM..
caps_phisto is offline     Reply With Quote
Old 11-06-2004, 02:13 PM   #4
amfoster
Member
 
Registered: Aug 2004
Distribution: debian, SuSE
Posts: 365
Thanked: 0
sed would work too

sed '/searchpattern/d' filename >newfile
amfoster is offline     Reply With Quote
Old 11-06-2004, 03:31 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :}
Posts: 18,850
Blog Entries: 1
Thanked: 160
And just so awk doesn't fall aside ...

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

awk is absolutely awksome! :)


Cheers,
Tink
Tinkster is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Awk command-line arguments lowpro2k3 Programming 1 03-28-2005 10:09 PM
problem deleting file using solaris command line. szehanz Solaris / OpenSolaris 2 03-22-2005 08:52 PM
deleting characters at the beginning of a line poobeany Programming 6 09-23-2003 06:17 PM
deleting a file via comman line PionexUser Linux - General 2 09-17-2003 01:27 AM
awk/gawk handling of "delete" ? realos Programming 1 06-26-2003 10:45 AM


All times are GMT -5. The time now is 06:56 PM.

Main Menu
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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration