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
PERL: Searching for a string in a text file problem meevagh Shell Programming and Scripting 15 05-01-2008 10:57 AM
searching for a string in a file ROOZ UNIX for Dummies Questions & Answers 2 03-07-2008 01:54 PM
Extracting a string from one file and searching the same string in other files mohancrr Shell Programming and Scripting 1 09-19-2007 03:17 AM
Complicated string searching in a file nir_s Shell Programming and Scripting 5 09-21-2005 07:51 AM
searching for a string though file system peter.herlihy UNIX for Dummies Questions & Answers 3 12-06-2001 04:19 AM

 
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
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 09-14-2007
pondlife pondlife is offline
Registered User
  
 

Join Date: May 2004
Location: UK
Posts: 85
Perl: searching for a string in a file...

Hi All,

I need to search for a string in a file that I've opened and base a decision on the result. The logic is this:

"if the word 'Shared' appears on the first line then

do this on the whole file

else

do this on the whole file

"

The code I currently have isn't working:

Code:
           
if ($. = 1 && $_ =~ /^*Shared*$/) {

             $_ if ($awk - $F) . "\",\"";if ($. != 1) {
             $n = substr($Fld[11], 1, length($Fld[11]) - 2);
             $lines{$. - 1} = $n;

             }
           } else {

             $_ if ($awk - $F) . "\",\"";if ($. != 1) {
             $n = $Fld[10];
             $lines{$. - 1} = $n;

             }
           }
The pattern matching in this code was provided by using a2p (I know awk better than I know perl)...

Thanks in advance.
 

Bookmarks

Tags
perl, perl shift, regex, regular expressions, shift, shift perl

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 01:41 PM.


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