script.pl with sed shell calls: sh error syntax error near unexpected token `('
Hi,
Just my second cry for help here, so be gentle! I am using sed to do a substitution. The target strings in myfile are Code:
@stuffdeleted#TGACCA/1 Code:
cat myfile | sed 's_\(#[TCGA]\{6\}\)/1_\1/TESTSUSTUTIONVALUE2_g' Code:
@stuffdeleted#TGACCA/TESTSUBSTUTIONVALUE2 So far so good. And then I put it into a perl script. And it breaks. The error code is widely posted online but I haven't found a code context that's comparable to my code. Code:
sh: -c: line 0: syntax error near unexpected token `(' Code:
my $sed2cmd = "sed 's_\(#[TCGA]\{6\}\)/1_\1/2_g'"; Code:
my $cmdreads2 = "awk \'{print \$1$kNL \$5$kNL \$7 | \"$sed2cmd > $read2\.test\.sync\"}\' $read1\.join\.tmp"; $sed2cmd is being interpolated (?expanded?) correctly into the second command but sh doesn't like it. Neither do I (having spent 'quite a bit' of time on it )-: I'd appreciate suggestions. Solutions would be even better! I'm guessing this is going to be real simple .... Regards m |
It would be interesting/enlightening to me if you could
explain why you use "text processing tools" like sed & awk from within the "Swiss army knife" of data mangling. If you could explain what the perl script does as a whole, w/ some actual data (before & after processing examples) .... maybe the thing can be done w/o external programs and the problems quoting and escaping introduces? Cheers, Tink |
Quote:
Try something like: Code:
$variable =~ s_\(#[TCGA]\{6\}\)/1_\1/TESTSUSTUTIONVALUE2_g; |
@Tinkster
(-: OK answer_1: probably because I don't know any better; I'm a beginner answer_2: because text processing tools seem useful, and play is a good way to learn; yes I probably could do it all using Perl but how much fun would that be? answer_3: because my supervisor does it (so it must be right, huh?) answer_4: retraining by learning nix/perl/awk/sed/R among others delivers a hard-to-resit temptation to use them all in everything (be glad I didn't work some R and Java in there) take your pick! I can't share the data because they're not mine, and include details that would be trivial to track back to origin; a bad scene would surely follow. I've just seen TBOne's comment, which I will explore (didn;t know about sed built into perl, see?) I was nontheless under the impression that these system tools awk sed were inherently faster at munching through large files (eg 20million lines) than a perl while(<>) loop. Is that not right? |
Quote:
If it was me, I'd try it both ways...perl-only, and time it, then you can pre-parse the data using the cat/sed method, then run THAT input data through the perl program, and see which is quicker. But at 20 mil. lines of input data, you're going to be waiting anyway. Also, the beauty of doing it perl-only, is that you then have the $variable defined as the line with your changes, and the line without your changes is what fed it. So, doing multiple substitutions becomes a trivial change, if your data output needs change later. |
please, don't use sed and awk from perl.
it's not big or clever, to be honest it just makes you look silly ;) There's nowt wrong with programming for fun but it's more fun if you try and do it well. Michelangelo didn't paint the thingy chapel with a bread knife and a screwdriver did he? (You need to get a new supervisor). |
OK ... but
Quote:
But I find that calling awk and sed etc from perl is pretty rife in this field (informatics processing of data from next generation DNA sequencing machines). I have .pl scripts from 5 different sources which not only make calls on awk and sed but also on system sort(). Following the earlier comments on this thread I have started in on a 100% perl version of what I'm trying to do; it's waaaaaaay less compact than a version calling on awk and system sort. If perl is used merely as the glue/wrapper to make these various system calls ... is it really so bad? Is it really the equivalent of hacking at the ceiling of the Sistine Chapel with a waney-edged knife and 'driver? I'm a learner, so here to listen, learn, be guided. But it seems to me that the minimal perl script calling system tools does at least - and compactly - get the jobs done (or it would do if I could get that quoting issue sorted :-) further guidance always welcomed ... m |
Longer to write, faster to execute ?
You can test script mods with time command, like : time script.pl |
All times are GMT -5. The time now is 02:43 AM. |