How to selectively suppress perl output?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to selectively suppress perl output?
# 8  
Old 01-30-2012
Quote:
Originally Posted by LessNux
...
Code:
#!/bin/bash
set -f
vLn='bb cc dd'
echo $vLn | \
perl -pe 'my @vAry = glob; foreach my $i (@vAry) {print "$i\n";}'

...
I would like the entire perl statement to output the following.
bb
cc
dd

However, the actual output from the entire perl statement is
bb
cc
dd
bb cc dd

How can one suppress the output from the first perl substatement?
...
Are you okay with removing the "p" switch?
It's similar to the "n" switch, but it prints the input line by default (similar in function to the "p" switch of sed).

For example, if your shell script were like so -

Code:
$
$
$ cat -n bash_to_perl.sh
     1  #!/bin/bash
     2  set -f
     3  vLn='bb cc dd'
     4  echo $vLn | \
     5  perl -pe ''
$
$

then the output will be the value of $vLn, even when you are doing nothing in your Perl one-liner -

Code:
$
$ cat -n bash_to_perl.sh
     1  #!/bin/bash
     2  set -f
     3  vLn='bb cc dd'
     4  echo $vLn | \
     5  perl -pe ''
$
$
$ ./bash_to_perl.sh
bb cc dd
$
$

If you use the "n" switch instead, then -

Code:
$
$
$ cat -n bash_to_perl.sh
     1  #!/bin/bash
     2  set -f
     3  vLn='bb cc dd'
     4  echo $vLn | \
     5  perl -ne 'my @vAry = glob; foreach my $i (@vAry) {print "$i\n";}'
$
$
$ ./bash_to_perl.sh
bb
cc
dd
$
$

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Selectively deleting newlines with sed

I have a file that look like this: >Muestra-1 agctgcgagctgcgaccc gggttatata ggaagagacacacacaccccc >Muestra-2 agctgcg agctgcgacccgggttatataggaagagac acacacaccccc >Muestra-3 agctgcgagctgcgaccc gggttatata ggaagagacacacacaccccc I use the following sed script to remove newlines from... (2 Replies)
Discussion started by: Xterra
2 Replies

2. Shell Programming and Scripting

How to selectively NOT output some fileds?

Dear All I have a text file which has many columns (>10,000). I want to create a new text file which will NOT include following columns: 5,15,105,200. How can I do that in shell (or awk, perl)? Thanks. (6 Replies)
Discussion started by: littlewenwen
6 Replies

3. Shell Programming and Scripting

Perl help - how to assign output of perl to variable

Hi, guys, i have a script i inherited from a coworker but i'm not perl savy. The script works but i would like it to work better. I want to run this command ./ciscomgrtest.pl -r "show version" -h hosts.router and have the script goto each router in the hosts.router file and run the command... (2 Replies)
Discussion started by: whipuras
2 Replies

4. Shell Programming and Scripting

Awk or Perl - to selectively merge two files.

I have two files, these have to be selectively merged into two other files. In addition there will require to be a edit to the last field, where the date format is changed. The first file is a csv file with around 300k lines the data is now nearly 20 years old and I have been asked to move this... (7 Replies)
Discussion started by: gull04
7 Replies

5. Shell Programming and Scripting

Remove EOL selectively

Hi, I have a text as below test1 test2 test3\ test4 test5 test6 test7 newtest1 newtest2\ newtest3 newtest4 newtest5 And need this to be replaces to test1 test2 test3 test4 test5 test6 test7 newtest1 newtest2 newtest3 newtest4 newtest5 So my requirement is to remove the EOL... (5 Replies)
Discussion started by: praveenbvarrier
5 Replies

6. Shell Programming and Scripting

Suppress the output of ping

Hi All, I just wanted to know, is there a way to suppress the output of the following i.e. the output should not be written on the screen: ping 10.1.23.234 -n 1 PING 10.1.23.234: 64 byte packets 64 bytes from 10.1.23.234: icmp_seq=0. time=0. ms ----10.1.23.234 PING Statistics---- 1... (2 Replies)
Discussion started by: ss_ss
2 Replies

7. Shell Programming and Scripting

how to suppress dd output?

I have to stop the output of dd from writing to terminal. Here is the command: sudo dd if=boot1h of="/dev/r$temp1" Here is the output: 2+0 records in 2+0 records out 1024 bytes transferred in 0.000804 secs (1273715 bytes/sec) I have tried >> log.txt but it doesn't work. Is there... (4 Replies)
Discussion started by: msf5042
4 Replies

8. Shell Programming and Scripting

how to suppress list number from history command output

i run history command and I want to eliminate the list number. So far this perl script works as long as the list is a exact 3 character long. cat dd | perl -pe 's,\d{3},,' 70 export JAVA_HOME=. 81 export JAVA_HOME=. 82 export JAVA_HOME=`pwd` export JAVA_HOME=`pwd` ... (1 Reply)
Discussion started by: soemac
1 Replies

9. Shell Programming and Scripting

how to selectively mount FS?

Hi all, I have this doubt as to whether we can selective mount FS .by taking the input from the vfstab? ie, suppose i want to mount tmpfs(actually i want to do it :))but i dont want to follow the conventional way through the script that actually does!! However i want to just collect that... (0 Replies)
Discussion started by: wrapster
0 Replies

10. Shell Programming and Scripting

flags to suppress column output, # of rows selected in db2 sql in UNIX

Hello, I am new to db2 SQL in unix so bear with me while I try to explain the situation. I have a text file that has the contents of the where condition that I am using for a db2 SQL in UNIX ksh. Here is the snippet. if ; then echo "Begin processing VALUEs" ... (1 Reply)
Discussion started by: jerardfjay
1 Replies
Login or Register to Ask a Question