Perl command in bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl command in bash
# 8  
Old 03-28-2015
I use a perl script to add specific text to specific columns in a text file. A new file gets created in the location listed below but it is empty. So I am not sure if the script itself is incorrect or if the input file is not being used. Below is how I call the perl script:

I provide the full path to the .pl , the input and the output

Code:
 perl 'C:\Users\cmccabe\Desktop\annovar\matrix.pl' < "${id}".txt.hg19_multianno.txt > "L:\NGS\3_BUSINESS\Matrix\Torrent\matrix_"${id}".txt"

The overall goal is use ${id}.txt.hg19_multianno.txt as the input file and after the perl script is run on that file (which adds the columns and text) and the new file is saved to the path L:\NGS\3_BUSINESS\Matrix\Torrent\matrix_${id}.txt . That path is a static path and will never change, there is probably a better way but I am not expert enough to know. I attached the .pl as well. Thank you

Last edited by Don Cragun; 03-28-2015 at 03:04 PM.. Reason: Fix ICODE tags.
# 9  
Old 03-28-2015
Your Perl program is broken. The first 49 "if" statements do not have their closing braces. A part of your script is shown below with the problem:

Code:
  ...
  ...
  if ( $. == 1 ) {  <== this opening brace does not have a corresponding closing brace
    s/$/ Index/;
  if ( $. == 2 ) { <== this opening brace does not have a corresponding closing brace
    s/$/ Chromosome Position/;
  ...
  ...

As a result the Perl script, when run, will fail and abort with a compile time error similar to the following (I've put the 3 dots below (...), but you'll see some information instead of the dots):

Code:
Missing right curly or square bracket at ...
syntax error at ...
Execution of ... aborted due to compilation errors.

(1) The reason you are seeing a file in your L:\NGS location is because that is done by your shell. When you put a redirection operator "> some_file", the shell immediately creates a 0-byte file at that moment in that location.

(2) And the reason the file at L:\NGS is empty is because the Perl program does not work. It fails with the error and does not print anything in the standard output (STDOUT) that could go to the L:\NGS file.

Now, you should be able to see the error message thrown by Perl. I'm not sure why you're not.

Maybe you are calling your Bash shell script like so?

Code:
my_shell_script.sh 2>/dev/null

That will redirect all error messages into the NULL device and you won't see the error message spewed by Perl.

To fix the problems:

(1) Ensure that the Perl program is correct syntax-wise. All opening braces must have corresponding closing braces.

(2) Replace this line in your shell script:

Code:
perl 'C:\Users\cmccabe\Desktop\annovar\matrix.pl' < "${id}".txt.hg19_multianno.txt > "L:\NGS\3_BUSINESS\Matrix\Torrent\matrix_"${id}".txt"

by this:
Code:
perl 'C:\Users\cmccabe\Desktop\annovar\matrix.pl' < "${id}".txt.hg19_multianno.txt

and run your shell script without the "2 >/dev/null" (if it is so now).
That should print the output to your screen (terminal). If it looks satisfactory, then add the "> L:\NGS\..." part to it.
This User Gave Thanks to durden_tyler For This Post:
# 10  
Old 03-30-2015
Thank you, the perl scripts runs but the results are not as expected. The .pl attached is supposed to add the text to the specific columns, but it is not and I'm not sure why or if there is a better way.

Basically, ${id}.txt.hg19_multianno.txt is the input file and after the perl script is run on that file (which adds the columns and text) and the new file is saved to the path L:\NGS\3_BUSINESS\Matrix\Torrent\matrix_${id}.txt

I also attached the desired results as an excel with the yellow color being the text/fields added by the script and the green are the text/fields in the original file. Thank you Smilie.
# 11  
Old 03-30-2015
In the Perl script you add strings to the end of specific lines.

$.
is the line number

$ in a substitution is the end of the current line.

So you're adding strings to the end of some lines rather than amending columns.
# 12  
Old 03-30-2015
Refering to your "output.xls" file in the previous post, are the following assumptions correct?

(1) The data in the range S1:AP87 in the "Test" worksheet is in your "${id}.txt.hg19_multianno.txt" file already.

(2) You want to add the data in the range A1:R87 to the left of the existing data.

(3) You want to add the data in the range AQ1:AX87 to the right of the existing data.

If the assumptions above are correct, then:

(a) From where do you get the data in the range A2:R87?
(b) And from where do you get the data in the range AQ2:AX87?
# 13  
Old 03-30-2015
Only the header text is needed. The attempted perl script was only going to add these columns.

So basically,

Code:
 A1 = Index, B1 = Chromosomal Position, C1 = etc...

The only columns with data come from "${id}.txt.hg19_multianno.txt". Thank you Smilie.
# 14  
Old 03-30-2015
I don't think I understood this statement:
Quote:
Originally Posted by cmccabe
...The only columns with data come from "${id}.txt.hg19_multianno.txt". ...
Do you mean:

(a) the "${id}.txt.hg19_multianno.txt" file has only one line similar to this?

Code:
Chr Start ... clinvarsubmit clinvarreference

And you want to change it to this?

Code:
Index Chromosome ... Amino Acid Change Chr Start ... clinvarsubmit clinvarreference HP SPLICE ... Sanger References

Or

(b) the "${id}.txt.hg19_multianno.txt" file has a header line like this?

Code:
Chr Start ... clinvarsubmit clinvarreference

and data (from line no. 2 onwards) similar to the range A2:AX87 in the "Test" worksheet of your Excel workbook "output.xls".
And you want to convert the header to this:

Code:
Index Chromosome ... Amino Acid Change Chr Start ... clinvarsubmit clinvarreference HP SPLICE ... Sanger References

and keep the data as it is (i.e. just iterate from line no. 2 onwards till end of file without making any changes)?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run several bash commands put in bash command line?

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)
Discussion started by: abdulbadii
4 Replies

2. Shell Programming and Scripting

How to call a bash command from within a perl script?

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)
Discussion started by: LessNux
1 Replies

3. UNIX for Dummies Questions & Answers

Running set options from the command line and bash command

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)
Discussion started by: Straitsfan
5 Replies

4. AIX

Typing "bash" at the command line spawns two bash processes

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)
Discussion started by: wjssj
2 Replies

5. Shell Programming and Scripting

perl/unix: script in command line works but not in perl

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)
Discussion started by: kpddong
2 Replies

6. Shell Programming and Scripting

Calling bash command in perl script

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)
Discussion started by: sQew
12 Replies

7. Shell Programming and Scripting

combine two perl lines into a single perl command

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)
Discussion started by: jimmy_y
4 Replies

8. Shell Programming and Scripting

Mixing Perl with Bash

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)
Discussion started by: kermit
2 Replies

9. Shell Programming and Scripting

[Perl] Accessing array elements within a sed command in Perl script

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)
Discussion started by: userix
2 Replies

10. Shell Programming and Scripting

passing variable from bash to perl from bash script

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)
Discussion started by: arsidh
10 Replies
Login or Register to Ask a Question