LinuxQuestions.org
Visit the LQ Articles and Editorials section
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
 
LinkBack Search this Thread
Old 11-05-2004, 06: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

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:
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.
 
Old 11-05-2004, 07:21 PM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 3,988

Rep: Reputation: 261Reputation: 261Reputation: 261
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
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

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
amfoster
Member
 
Registered: Aug 2004
Distribution: debian, SuSE
Posts: 365

Rep: Reputation: 34
sed would work too

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

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

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

awk is absolutely awksome! :)


Cheers,
Tink
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are 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


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

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
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration