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
Search for multiple strings and mail accordingly AnneAnne UNIX for Dummies Questions & Answers 3 03-12-2009 10:14 AM
How to search multiple strings in a file deepakpv Shell Programming and Scripting 2 09-19-2008 03:02 AM
Problem to search multiple strings sudhish Shell Programming and Scripting 2 10-25-2007 02:00 PM
Print lines with search string at specific position HealthyGuy Shell Programming and Scripting 4 12-04-2006 09:47 AM
How to insert strings at certain position whatisthis Shell Programming and Scripting 14 11-14-2005 06:40 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 03-18-2009
HugoH HugoH is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 6
Search for multiple strings in specific position

Hi,

I need to search for some strings in specific positions in a file.

If the strings: "foo1", "foo2" or "foo3" is on position 266 or position 288 in a file i want the whole line printed.


Any idea how to do it?
  #2 (permalink)  
Old 03-18-2009
swatij16 swatij16 is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 1
Hi

you can use grep -x for finding specific string in file.
  #3 (permalink)  
Old 03-18-2009
HugoH HugoH is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 6
But i cannot specify the position then?

The strings may be at more places but they are only interesting if they are in this positions.
  #4 (permalink)  
Old 03-18-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
With some hardwiring, but... something to start with:
Code:
nawk -v str='foo1|foo2|foo3' 'substr($0, 266, 4) ~ str || substr($0, 288, 4) ~ str' myFile
  #5 (permalink)  
Old 03-18-2009
HugoH HugoH is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 6


Thanks, thanks & thanks again!

It solved my problem.

  #6 (permalink)  
Old 03-18-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
a more generic solution:

nawk -v str='foo1 foo2 foo3' -v pos='266 288' -f hugo.awk myFile

hugo.awk:
Code:
BEGIN {
   split(str, strA, FS)
   split(pos, posA, FS)
}
{
   for(strI=1; strI in strA; strI++)
      for(posI=1; posI in posA; posI++)
        if ( posA[posI] == match($0, strA[strI]) ) {
           print
           next
        }
}

Last edited by vgersh99; 03-18-2009 at 12:13 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 06:39 PM.


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