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
using AWK see the upper lines and lower lines of the strings?? thepurple Shell Programming and Scripting 3 10-07-2008 10:24 AM
list and export strings in a file Avatar Gixxer Shell Programming and Scripting 3 09-19-2008 06:41 AM
Perl RegExp to remove last character from strings ospreyeagle Shell Programming and Scripting 2 04-03-2008 02:55 PM
matching characters between strings akmtcs UNIX for Dummies Questions & Answers 9 12-08-2006 09:04 AM
Remove Carriage returns between strings in a field acheepi Shell Programming and Scripting 10 09-24-2005 01:19 PM

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

Join Date: Feb 2008
Posts: 16
Question Remove matching lines with list of strings

Hi,
HP-UX gxxxxxxxc B.11.23 U ia64 3717505098 unlimited-user license
I have a file with below pipe separated field values:

xxx|xxx|abcd|xxx|xxx|xx
xxx|xxx|abcd#123|xxx|xxx|xx
xxx|xxx|abcd#345|xxx|xxx|xx
xxx|xxx|pqrs|xxx|xxx|xx
xxx|xxx|pqrs#123|xxx|xxx|xx

The third field has values like abcd and pqrs. I need a file with lines only with abcd and pqrs. The other lines that have abcd#123, abcd#345 should be removed. Same for pqrs field also. This is a huge file and many in numbers. So, I need some expert suggestion to have an efficient solution.

I have used awk -F"|" '{print $3}' | grep -v "#". It only gives me abcd and pqrs. I need the corresponding lines in a separate file. My output file should be:

xxx|xxx|abcd|xxx|xxx|xx
xxx|xxx|pqrs|xxx|xxx|xx

I have a great respect to the knowledgeable participants and their willingness to help in this forum and also I have taken a lot of help in finding my answers in the past from you guys. I know I can't be let down. Please help, it is important for me to remain as a developer. Thanks in advance.

Manjax
  #2 (permalink)  
Old 10-15-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink Is this what you are trying to do?

Code:
> cat file98
xxx|xxx|abcd|xxx|xxx|xx
xxx|xxx|abcd#123|xxx|xxx|xx
xxx|xxx|abcd#345|xxx|xxx|xx
xxx|xxx|pqrs|xxx|xxx|xx
xxx|xxx|pqrs#123|xxx|xxx|xx

> awk -F"|" '$3=="abcd" || $3=="pqrs" {print}' file98
xxx|xxx|abcd|xxx|xxx|xx
xxx|xxx|pqrs|xxx|xxx|xx

> awk -F"|" '$3!="abcd" && $3!="pqrs" {print}' file98
xxx|xxx|abcd#123|xxx|xxx|xx
xxx|xxx|abcd#345|xxx|xxx|xx
xxx|xxx|pqrs#123|xxx|xxx|xx
or

Code:
> awk  'BEGIN {FS="|"} $3=="abcd" || $3=="pqrs" {print}' file98
xxx|xxx|abcd|xxx|xxx|xx
xxx|xxx|pqrs|xxx|xxx|xx

> awk  'BEGIN {FS="|"} $3!="abcd" && $3!="pqrs" {print}' file98
xxx|xxx|abcd#123|xxx|xxx|xx
xxx|xxx|abcd#345|xxx|xxx|xx
xxx|xxx|pqrs#123|xxx|xxx|xx

Last edited by joeyg; 10-15-2008 at 04:24 PM.. Reason: Added two more awk commands
  #3 (permalink)  
Old 10-15-2008
Nanu_Manju Nanu_Manju is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 16
Question Remove matching lines with list of strings

Hi,

I should mention that the strings may be anything. abcd and pqrs were just examples. All I know is that there is a third field string with and without #. I need lines without #. Hope we are on the same page. Thanks for the quick come back.

Manjax
  #4 (permalink)  
Old 10-15-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Code:
grep '^[^|]*\|[^|]*\|[^#|]*\|' infile>outfile
If you grep implementation supports re-interval (like /usr/xpg4/bin/egrep on Solaris and GNU grep):

Code:
egrep '^([^|]*\|){2}[^#|]*\|' infile>outfile

Last edited by radoulov; 10-16-2008 at 03:59 AM.. Reason: corrected
  #5 (permalink)  
Old 10-29-2008
Nanu_Manju Nanu_Manju is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 16
Thumbs up Thank you very much

Hi all,

Firstly, I am extremely sorry that I was late to reply and say thanks. Everytime I log out from this site happily. Thanks guys, keep up the good work. You people are wonderful.

Regards,
Manjax
  #6 (permalink)  
Old 10-29-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,079
Code:
nawk -F"|" '($3 ~ /^abcd$/ || $3 ~/^pqrs$/){print}' filename
Closed Thread

Bookmarks

Tags
lines, list of strings, remove, strings list

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 12:08 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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