The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to delete this? kenshinhimura Shell Programming and Scripting 1 07-02-2008 06:52 AM
how to delete content in a file (delete content only) kittusri9 Shell Programming and Scripting 5 05-15-2008 01:12 PM
delete in c++ nandlal High Level Programming 4 02-02-2008 12:48 PM
C++ = new and delete arun.viswanath High Level Programming 3 09-13-2005 10:16 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-12-2008
uwork72 uwork72 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 32
Delete help

Please give me some hints with awk or something, to delete the lines corresponding to a fixed 2nd field, for which A line is absent.

Code:
$ cat file.txt
#Test file

a 1 2232 ert
a 1 679 asd
A 1 12 oio

a 2 131 sd
a 2 56 adsad
a 2 567 sassa
A 2 90 asd

a 4 234 gfg
a 4 566 erer


a 5 233 yu
A 5 232 yuyu
So the required output is something like this for the above file:

Code:
#Test file

a 1 2232 ert
a 1 679 asd
A 1 12 oio

a 2 131 sd
a 2 56 adsad
a 2 567 sassa
A 2 90 asd

a 5 233 yu
A 5 232 yuyu
Thank you.
  #2 (permalink)  
Old 10-12-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,793
Use nawk or /usr/xpg4/bin/awk on Solaris:


Code:
awk '/A /' ORS='\n\n' RS= filename
Or better:

Code:
perl -00 -nle'/^A/m and print' filename
  #3 (permalink)  
Old 10-12-2008
uwork72 uwork72 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 32
Thanks radoulov for your reply. Thanks.

Could you also suggest how can I keep any other lines (e.g. in the above file the line "#Test file" or any other intermediate comment lines) in the output.
Thanks.
  #4 (permalink)  
Old 10-12-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,793
Code:
perl -00 -nle'print unless/^a.*\n^a/im&&!/^A/m' filename
Edit: Just saw you want only the comments, so it depends, you may try something like this:

Code:
perl -00 -nle'/^[A#]/m and print' filename
But it will fail on an input like this:

Code:
# 
a 4 234 gfg
a 4 566 erer
With AWK you can try something like this, but it will fail in too many situations:

Code:
awk '/[A#] */' ORS='\n\n' RS= filename

Last edited by radoulov; 10-12-2008 at 04:17 PM..
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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



All times are GMT -4. The time now is 04:41 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0