How to selectively suppress perl output?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to selectively suppress perl output?
# 1  
Old 01-30-2012
Question How to selectively suppress perl output?

The following perl statement in a bash script consists of two substatements. I intend the first perl substatement (the assignment with glob) to get input from the preceding bash pipe, and the second perl substatement (the foreach loop) to output back to bash. However, the first perl substatement undesirably outputs back to bash in addition to the desirable output from the second perl substatement. I want only the second perl substatement to output back to bash. Please show me how to prevent the first perl substatement from outputting to bash.

Code:
#!/bin/bash
set -f
vLn='bb cc dd'
echo $vLn | \
perl -pe 'my @vAry = glob; foreach my $i (@vAry) {print "$i\n";}'


The perl statement consists of
my @vAry = glob
and
foreach my $i (@vAry) {print "$i\n";}


The output from the first perl substatement is
bb cc dd

The output from the second perl substatement is
bb
cc
dd

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?

Many thanks in advance.


Update:

This question has been successfully answered by Post#8 by durden_tyler.

Last edited by LessNux; 01-30-2012 at 10:50 PM..
# 2  
Old 01-30-2012
If you're trying to print those three words vertically, you may try this:
Code:
$ x='bb cc dd'
$ echo $x | sed "s/ /\n/g"
bb
cc
dd

# 3  
Old 01-30-2012
Quote:
Originally Posted by balajesuri
If you're trying to print those three words vertically, you may try this:
Code:
$ x='bb cc dd'
$ echo $x | sed "s/ /\n/g"
bb
cc
dd



That is not what I want. I need perl definitely. I need communication between bash and perl.
# 4  
Old 01-30-2012
Code:
#! /bin/bash
x='bb cc dd'
echo $x | perl -le '@x=split/\s+/,<>; print for (@x)'

# 5  
Old 01-30-2012
Code:
$ echo  $x | perl -lane '$_=~s/ /\n/g;print $_'
bb
cc
dd

# 6  
Old 01-30-2012
@itkamaraj: If -a switch is used, we could also do this:
Code:
echo  $x | perl -lane 'print for (@F)'

This User Gave Thanks to balajesuri For This Post:
# 7  
Old 01-30-2012
Do not remove "glob", please!
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