The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
search excat string in another string (grep "fails") bora99 UNIX for Dummies Questions & Answers 0 06-05-2008 03:41 AM
Search, replace string in file1 with string from (lookup table) file2? gstuart Shell Programming and Scripting 2 04-11-2008 11:32 AM
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 07:24 AM
Search for a string sumesh.abraham Shell Programming and Scripting 12 12-11-2006 06:29 AM
appending string to text file based on search string malaymaru Shell Programming and Scripting 1 06-09-2006 05:53 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-07-2008
Registered User
 

Join Date: Jan 2008
Posts: 14
search string

Hi ,
I need to right a script in which I need to search for a string, which is at 11th column fields saperated by "|" and delete all the lines from the file which contains that string .

Please help
Reply With Quote
Forum Sponsor
  #2  
Old 02-07-2008
Registered User
 

Join Date: Apr 2007
Location: Kolkata
Posts: 81
Thumbs up

Dear viv1,

try this

awk -F'|' 'BEGIN{
while(getline < "filename1")
{
if ( $11 != <SEARCH STRING>)
{
print $0
}
}
}' >> filename2

filename1 will be ur input file and filename2 will be ur output file in which u'll redirect the output. "SEARCH STRING" will be the string u want to search for.

Regards,
Pankaj
Reply With Quote
  #3  
Old 02-07-2008
Registered User
 

Join Date: Apr 2007
Location: Kolkata
Posts: 81
Thumbs up

u can do it in one line also

awk -F'|' 'BEGIN{while(getline < "filename1"){if ( $11 != <SEARCH STRING>){print $0}}}' >> filename2


Regards,
Pankaj
Reply With Quote
  #4  
Old 02-07-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Code:
# awk -F"|" s="$searchstring"  '$11!=s' file
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:29 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0