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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How do I search for 2 strings (AND operator) ? Kartheg UNIX for Dummies Questions & Answers 14 09-11-2009 05:44 PM
search a logfile for strings amitrajvarma UNIX for Dummies Questions & Answers 0 11-25-2007 10:09 AM
Search between strings with an OR pbsrinivas Shell Programming and Scripting 3 07-12-2007 05:46 AM
awk search for Quoted strings (') kprattip Shell Programming and Scripting 13 07-10-2007 04:30 PM
Search for strings lesstjm UNIX for Dummies Questions & Answers 5 04-26-2002 10:58 AM

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 03-10-2008
syamkp syamkp is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 8
how to search with 2 strings.

Hi,
i have a file a.txt like
--------------------------------
col1|col2|col3
data1|data2|data3
other1|other2|other3
--------------------------------

i need to search 2 strings(data in a.txt file is case sesnsitive), suppose data1 and data2. If these 2 strings found then only i need to update data3 string with data4 string. If not found then i have to echo some message(No data found).

Pls provide me some solution for this.
Thanks in advance.
  #2 (permalink)  
Old 03-10-2008
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Quote:
Originally Posted by syamkp View Post
Hi,
i have a file a.txt like
--------------------------------
col1|col2|col3
data1|data2|data3
other1|other2|other3
--------------------------------

i need to search 2 strings(data in a.txt file is case sesnsitive), suppose data1 and data2. If these 2 strings found then only i need to update data3 string with data4 string. If not found then i have to echo some message(No data found).

Pls provide me some solution for this.
Thanks in advance.
Code:
grep -E "data1|data2" a.txt
if [[ $? -eq 0 ]] ; then
  sed -e "s/\(data1|data2|\).*/\1data4/g" a.txt
else
  echo "No data1|data2 in a.txt"
fi
  #3 (permalink)  
Old 03-10-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,088
Code:
nawk '{
if (index($0,"data1")!=0 && index($0,"data2")!=0)
{
sub(/data3/,"data4",$0)
print
}
else
print
}' filename
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 12:23 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