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
Piping Question mtobin1987 High Level Programming 2 04-26-2008 12:24 AM
Piping in UNIX simo007 UNIX for Dummies Questions & Answers 3 05-23-2007 03:40 AM
Help with piping program PuppyHusher High Level Programming 3 03-30-2007 01:26 PM
piping lnatz Shell Programming and Scripting 1 07-14-2006 03:30 AM
Help (Piping ls, tr, cut) scan Shell Programming and Scripting 2 02-11-2006 08:40 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 09-01-2008
Raynon Raynon is offline
Registered User
  
 

Join Date: Sep 2006
Location: Sg
Posts: 350
Piping in Perl

Hi All,

I am trying to perform the below csh code in Perl, but i am unfamiliar with Perl. Can anybody give me some advice on it ?

Csh Code:


Code:
cat filename |grep AAA| grep BBB| awk '{print("already_appended")'

  #2 (permalink)  
Old 09-01-2008
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,926

Code:
 
perl -lne'print "already_appended" if /AAA/ and /BBB/' filename

  #3 (permalink)  
Old 09-01-2008
sysgate's Avatar
sysgate sysgate is offline Forum Advisor  
Unix based
  
 

Join Date: Nov 2006
Location: Bulgaria
Posts: 1,323

Code:
if($string =~ m/(AAA|BBB|CCC)/)
  {print "We've got a match!\n"}

in the most common case.
  #4 (permalink)  
Old 09-03-2008
Raynon Raynon is offline
Registered User
  
 

Join Date: Sep 2006
Location: Sg
Posts: 350
Hi sysgate,

Think if($string =~ m/(AAA|BBB|CCC)/) is an OR function.

In short, the purpose of the below csh shell actually grabs the lines which contain both the term AAAand BBB.
However, the Perl code which you showed me will only grab those lines containing either AAA or BBB or both.

Can anybody give me some advice ?
Was wondering if the below Perl code can work ?


Code:
 if($_ =~ "AAA" && $_ =~ "BBB" ) 
{print "We've got a match!\n"}

  #5 (permalink)  
Old 09-03-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Yes, just like in the code Radoulov already posted above. ($_ is the default target for matching, so Radoulov left it out.)
  #6 (permalink)  
Old 09-03-2008
Raynon Raynon is offline
Registered User
  
 

Join Date: Sep 2006
Location: Sg
Posts: 350
Hi Era,

What if the terms we want to match is an array ?
I tried the below and it doesn;t seem to work.

Eg


Code:
 if($_ =~ @array_x[$num] && $_ =~ @array_y[$num] ) 
{print "We've got a match!\n"}

  #7 (permalink)  
Old 09-03-2008
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,926

Code:
 if (/$array_x[$num]/ && /$array_y[$num]/) {
   print "We've got a match!\n"
  }

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 07:13 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