... it appears to be the way that the input file is being read by the perl script. Is that right?...
That is right.
Quote:
Originally Posted by cmccabe
...It was the way it was called... I see now that the < input and > output are not needed:
...
Yes, you got it.
(a)
When you invoke
your shell passes the content of the file "my_file.txt". So your Perl program works only with the content; it doesn't have to open the file.
(b)
When you invoke
your shell passes the name of the file i.e. "my_file.txt". (Actually, it passes just a string, which happens to be the name of a file.)
Your Perl program will have to open the file first. Only then can it access the content of the file.
You were using method (a) earlier. I used method (b) in my post.
Quote:
Originally Posted by cmccabe
...However, the new file that is created only has the headers in it and doesn't carry over the data in the multianno.txt....
That's because the program is processing only one line - line number 1, or the header line. If you want it to process all lines, the required change is simple.
Check these pages for more information: last - perldoc.perl.org perlvar - perldoc.perl.org (Search for "$." in the box at the top right corner.)
The below seems to work, although it writes the header data to a file and outputs the data to the screen.
...
The portion of the code in red color i.e. the "while" loop will iterate through your entire file - i.e. the first line (the header) and all the lines after that (the data).
But the "if" part in green color processes only one line.
Did you figure out why that is so?
Quote:
Originally Posted by cmccabe
...
...
The part in red closes the input file after processing only one line.
The part in green writes to the output file.
The part in blue opens the input file again.
Why do you do that?
The "while" loop shown earlier is anyway iterating through your entire file.
Why not take advantage of that and do your processing for the header as well as the data? Why open the input file a second time?
How to run several bash commands put in bash command line without needing and requiring a script file.
Because I'm actually a windows guy and new here so for illustration is sort of :
$ bash "echo ${PATH} & echo have a nice day!"
will do output, for example:... (4 Replies)
In a bash script, one can call a perl command in the following manner, where "myperlcommand" is a perl command.
perl -e 'myperlcommand(arguments)'
perl -e 'print("UUUU"x4)'
Now, how can one call a bash command from within a perl script? (Suppose that mybashcommand is a bash... (1 Reply)
I'm reading about debugging aids in bash and have come across the set command. It says in my little book that an addition to typing
set
you can also use them "on the command line when running a script..." and it lists this in a small table:
set -o option Command Line... (5 Replies)
Server: IBM p770
OS: AIX 6.1 TL5 SP1
When one of our develoeprs types "bash" on the command line to switch shells, it hangs. For some reason, two bash processes are created....the first bash process spawns a second bash process in the same console, causing a hang. Anyone have any idea what... (2 Replies)
so in unix this command works works and shows me a list of directories
find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt
but when i try running a perl script to run this command
my $query = 'find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt';... (2 Replies)
Hi,
I have tried several times but failed, I need to call this script from the perl script. This one line script will be sent to /var/tmp/error
Bash command:
/usr/openv/netbackup/bin/admincmd/bperror -backstat -l -hoursago 12 |awk '{ print $19, $12, $14, $16}'|grep -vi default|sort >... (12 Replies)
Hi Everyone,
i have a string 00:44:40
so:
$tmp=~ s/://gi;
$tmp=~s/({2})({2})({2})/$1*3600+$2*60+$3/e;
the output is 2680.
Any way to combine this two lines into a single line?
Thanks (4 Replies)
I am fiddling with a little script that will issue a shutdown command if the temperature on the CPU goes above a certain level. I started writing the script in Bash, and then thought I would like to use Perl to extract the detailed bits, but I am not sure if this is really practical. Basically I... (2 Replies)
I am trying to use a script to replace the header of each file, whose filename are stored within the array $test, using the sed command within a Perl script as follows:
$count = 0;
while ( $count < $#test )
{
`sed -e 's/BIOGRF 321/BIOGRF 332/g' ${test} > 0`;
`cat 0 >... (2 Replies)
Hi All,
I need to pass a variable to perl script from bash script, where in perl i am using if condition. Here is the cmd what i am using in perl
FROM_DATE="06/05/2008"
TO_DATE="07/05/2008"
"perl -ne ' print if ( $_ >="$FROM_DATE" && $_ <= "$TO_DATE" ) ' filename"
filename has... (10 Replies)