Piping in Perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Piping in Perl
# 1  
Old 09-01-2008
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  
Old 09-01-2008
Code:
 
perl -lne'print "already_appended" if /AAA/ and /BBB/' filename

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

in the most common case.
# 4  
Old 09-03-2008
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  
Old 09-03-2008
Yes, just like in the code Radoulov already posted above. ($_ is the default target for matching, so Radoulov left it out.)
# 6  
Old 09-03-2008
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  
Old 09-03-2008
Code:
 if (/$array_x[$num]/ && /$array_y[$num]/) {
   print "We've got a match!\n"
  }

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Oneliner ---split string to character by piping shell output to perl

Hello, I was trying to split a string to characters by perl oneliner. echo "The quick brown fox jumps over the lazy dog" | perl -e 'split // ' But did not work as with bash script pipe: echo "The quick brown fox jumps over the lazy dog" | fold -w1 | sort | uniq -ic 8 1 T 1... (6 Replies)
Discussion started by: yifangt
6 Replies

2. Ubuntu

Piping with grep

Hi everybody, I have a big file with blast results (if you know what this means, otherwise look at it just as a text file with a specific form). I am trying to extract some ids from within this file, which have certain parameters. For example, some Of my IDs have the term 'No hit results'... (6 Replies)
Discussion started by: frymor
6 Replies

3. Ubuntu

Piping with grep

Hi everybody, I have a big file with blast results (if you know what this means, otherwise look at it just as a text file with a specific form). I am trying to extract some ids from within this file, which have certain parameters. For example, some Of my IDs have the term 'No hit results'... (1 Reply)
Discussion started by: frymor
1 Replies

4. Shell Programming and Scripting

Piping and assigning output to a variable in Perl

Hi All, I am trying to convert the below Csh code into Perl. But i have the following error. Can any expert help ? Error: ls: *tac: No such file or directory Csh set $ST_file = `ls -rt *$testid*st*|tail -1`; Perl my $ST_file = `ls -rt *$testid*st*|tail -1`; (10 Replies)
Discussion started by: Raynon
10 Replies

5. UNIX for Dummies Questions & Answers

Piping GREP

Hi, I need to use a double grep so to speak. I need to grep for a particular item say BOB and then for each successful result I need to grep for another item say SMITH. I tried grep "BOB" filename | grep "SMITH" but it does not seem to work. I can achieve my desired result using an... (12 Replies)
Discussion started by: mojoman
12 Replies

6. Programming

Piping Question

I have a piping question, I am trying to implement piping on my own shell and am having some trouble...esentially I am trying to make something to do command|command|command. I can get it to work fine if the last pipe command is not forked, but executes in the shell and then exits..but I need it... (2 Replies)
Discussion started by: mtobin1987
2 Replies

7. UNIX for Dummies Questions & Answers

Piping in UNIX

All, I am a UNIX novice with a question that I hope you can help me with. I have a UNIX application called "Tole" that formats and displays specific information about customers. I can display the information for up to 30 customers by seperating customer IDs using commas in this format: Tole -c... (3 Replies)
Discussion started by: simo007
3 Replies

8. Shell Programming and Scripting

Piping from device?

Hi Long time since I did any shell scripting so please be gentle with me! :) Just wanted to know whether it is possible to take the streaming output from a dvb card /dev/dvb/adapter0/ and using named pipes and tee to pass the outputs to mplayer and mencoder so as to watch and record a telly... (0 Replies)
Discussion started by: gary101
0 Replies

9. Shell Programming and Scripting

piping

I am using pipes (specifically piping out) in Perl to put an array from one file into an array in a different file. I can't figure out how to transfer the array. I kow how to open the pipe : open (FILEHANDLE, "| file") or die~ but how do I transfer the array. I think it has something to do with... (1 Reply)
Discussion started by: lnatz
1 Replies

10. Shell Programming and Scripting

Help (Piping ls, tr, cut)

I have to: pipe ls, tr, and cut to output the size (in bytes) and name of all of the files/dirs in the current directory (including any hidden ones), with the size at the beginning of the line, followed by a single tab character, followed by the the filename. I don't know what the point of... (2 Replies)
Discussion started by: scan
2 Replies
Login or Register to Ask a Question