The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Contact Us (Meet Our Management Team) > Post Here to Contact Site Administrators and Moderators
.
google unix.com



Post Here to Contact Site Administrators and Moderators Registered Users make ask questions and suggestions about forums, features, or content here. Get forum support here, not via email!!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search, replace string in file1 with string from (lookup table) file2? gstuart Shell Programming and Scripting 9 06-08-2009 07:11 AM
Search for a string sumesh.abraham Shell Programming and Scripting 14 01-09-2009 10:26 AM
search excat string in another string (grep "fails") bora99 UNIX for Dummies Questions & Answers 0 06-05-2008 07:41 AM
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 10:24 AM
appending string to text file based on search string malaymaru Shell Programming and Scripting 1 06-09-2006 09:53 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 02-13-2008
ajithshankar@ho ajithshankar@ho is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 3
Search String

Hi I have a file with multiple fields,

I want to search for two strings "DONOTUSE" and "DO NOT USE" from the first field.

Cand anyone help me how to do this...

Thnks,
Ajith
  #2 (permalink)  
Old 02-13-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
Cool

Here is a sample script. It checks for the existence of one of two five-character strings to match. If found on a line, will echo the line to the screen (you can do whatever you want with the echo). Also, I am setting the lines (al_pr1 & al_pr2) separately since it is unclear to me exactly how you want to match. (You mention field 1, but without a sample file it is difficult to determine how to define/match your first field. Lastly, I use in my sample the file called alarms, but you can use anything you want at that point.


#! /bin/bash

al_fl1="MULCT"
al_fl2="JUNCT"
while read alt
do
al_pr1=$(echo $alt | grep $al_fl1)
al_pr2=$(echo $alt | grep $al_fl2)
if [ -n al_pr1 -o -n al_pr2 ]
then
echo "$alt"
fi
done < alarms
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 09:40 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