Sponsored Content
Top Forums Shell Programming and Scripting perl: Command works in terminal, but not in shell script Post 302801595 by jdilts on Thursday 2nd of May 2013 09:53:19 AM
Old 05-02-2013
perl: Command works in terminal, but not in shell script

Hi, the following command works in the terminal no problem.
Code:
samtools view -h rawlib.bam | perl -ne '{ @line = split( /\s+/ ); $match = 0; while( $line[5] =~ /(\d+)M/g ) { $match = $match + $1 } if( $match >= 80 || $_ =~ /^\@/ ) { print $_ } }' | java -Xmx12G -jar /opt/picard/picard-tools-current/SortSam.jar I=/dev/stdin O=rawlib.gt80.bam VERBOSITY=WARNING QUIET=TRUE SO=coordinate; samtools index rawlib.gt80.bam

But when I plop it in a shell script and change the file names to given execution variables......
Code:
run "samtools view -h ${ANALYSIS_DIR}/${BARCODE_ID}_rawlib.bam | perl -ne '{ @line = split( /\s+/ ); $match = 0; while( $line[5] =~ /(\d+)M/g ) { $match = $match + $1 } if( $match >= 80 || $_ =~ /^\@/ ) { print $_ } }' | java -Xmx12G -jar /opt/picard/picard-tools-current/SortSam.jar I=/dev/stdin O=${ANALYSIS_DIR}/${BARCODE_ID}_rawlib.bam VERBOSITY=WARNING QUIET=TRUE SO=coordinate";samtools index ${ANALYSIS_DIR}/${BARCODE_ID}_rawlib.bam

I get an error.
Code:
running: samtools view -h /results/analysis/output/Home/user_LIS-27-06mar2013-40p12rpt-swp_4-12.2_207/AIB13-NA17281_rawlib.bam | perl -ne '{ @line = split( /\s+/ );  = 0; while( runplugin/runlevel	""[5] =~ /(\d+)M/g ) {  =  + -j } if(  >= 80 || /results/analysis/output/Home/user_LIS-27-06mar2013-40p12rpt-swp_4-12.2_207/AIB13-NA17281_oldrawlib.bam =~ /^\@/ ) { print /results/analysis/output/Home/user_LIS-27-06mar2013-40p12rpt-swp_4-12.2_207/AIB13-NA17281_oldrawlib.bam } }' | java -Xmx12G -jar /opt/picard/picard-tools-current/SortSam.jar I=/dev/stdin O=/results/analysis/output/Home/user_LIS-27-06mar2013-40p12rpt-swp_4-12.2_207/AIB13-NA17281_rawlib.bam VERBOSITY=WARNING QUIET=TRUE SO=coordinate
String found where operator expected at -e line 1, near "runlevel """
	(Do you need to predeclare runlevel?)
Bareword found where operator expected at -e line 1, near "06mar2013"
	(Missing operator before mar2013?)
Bareword found where operator expected at -e line 1, near "40p12rpt"
	(Missing operator before p12rpt?)
Bareword found where operator expected at -e line 1, near "06mar2013"
	(Missing operator before mar2013?)
Bareword found where operator expected at -e line 1, near "40p12rpt"
	(Missing operator before p12rpt?)
syntax error at -e line 1, near "; ="
syntax error at -e line 1, near "runlevel """
syntax error at -e line 1, near "( >="
syntax error at -e line 1, near "} }"
Execution of -e aborted due to compilation errors.

It looks as though the error starts occurring at
Code:
 $match = 0;

.
I've attached my code. Probably a syntax error?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl - how come this script works?

#!/usr/bin/perl open (DATA, file.txt); @array = <DATA>; close (DATA); open (DATA, ">$file.txt"); for (@array) { s/text/replace text/; push(@contents,$_); } seek(DATA, 0, 0); print DATA (@contents); close(DATA); could someone please explain how this works. i've been... (3 Replies)
Discussion started by: mjays
3 Replies

2. Shell Programming and Scripting

#!/bin/bash and #1bin/sh command not found error on mac osx terminal/shell script

i am having a weird error on mac os x running some shell scripts. i am a complete newbie at this and this question concerns 2 scripts. one of which a friend of mine wrote (videochecker.sh) a couple weeks ago and it's been running fine on another machine. then last week i wrote capture.sh and it... (2 Replies)
Discussion started by: danpaluska
2 Replies

3. 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

4. Shell Programming and Scripting

how the typeset command works in shell script

typeset -l section section=${2:-.} what does these 2 lines meaning? (1 Reply)
Discussion started by: venkatababu
1 Replies

5. Shell Programming and Scripting

help with shell script: cp command not working, but mv command works...

Hello. I would like to ask your help regarding the cp command. We are using a cp command to create a back-up copy of our file but to no avail. It's just not working. We already checked the file and directory permissions and all seems correct. We have a script (ftp.script) which calls on... (1 Reply)
Discussion started by: udelalv
1 Replies

6. Shell Programming and Scripting

SED command works in terminal, but not Applescript

The following command works perfectly in Terminal, but not in Applescript. (Returns "unknown token" error for square brackets.) (new to site. sorry.) I have an Applescript that is designed to find and remove any square-bracketed text, including the square brackets. I ran the following code from... (1 Reply)
Discussion started by: Phillip Acosta
1 Replies

7. UNIX for Dummies Questions & Answers

Shell script not working but command works in command prompt

Hi everyone I have a problem with my script If I try directly this command /usr/bin/nice -n 19 mysqldump -u root --password="******" wiki_schneider -c | nice -n 19 gzip -9 > /point_de_montage/$(date '+%Y%m%d')-wiki-db.sql.gz It works But if I simply add this command in a script and... (8 Replies)
Discussion started by: picemma
8 Replies

8. Shell Programming and Scripting

Perl error in batch command but works one at a time

In the below perl executes if one file is processed perfect. However, when multiple files are processed in batch which is preferred I get the below error that I can not seem to fix it as the '' necessary for the command to execute, but seem to only work for one -arg option. Thank you :). ... (2 Replies)
Discussion started by: cmccabe
2 Replies

9. Shell Programming and Scripting

Need to understand how the line in perl program works as shell commend

I have a file with two line, one is header, the other actual value: TYPCD|ETID2|ETID|LEG ID|PTYP|PTYP SUB|TRD STATUS|CXL REASON|CACT|CACTNM|ENCD|ENC D NM|TRDR|ASDT|TRDT|MTDT|STDT|LS|SECID|SECID TYP|SECNM|PAR|STCC|MARKET PRICE|DIS MARKET PRICE|MARKET PRICE CURRENCY|SRC OF SETTLEMENT... (2 Replies)
Discussion started by: digioleg54
2 Replies

10. Shell Programming and Scripting

Replace string works on command-line but fails when run from shell script

I wish to replace "\\n" with a single white space. The below does the job on command-line: $ echo '/fin/app/scripts\\n/fin/app/01/sql' | sed -e 's#\\\\n# #g'; /fin/app/scripts /fin/app/01/sql However, when i have the same code to a shell script it is not able to get me the same output:... (8 Replies)
Discussion started by: mohtashims
8 Replies
All times are GMT -4. The time now is 11:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy