Problem with cat with PERL Substitute


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Problem with cat with PERL Substitute
# 1  
Old 03-22-2007
Problem with cat with PERL Substitute

system("cat FILENAME | perl -e 'while(<>) { print $_;}'");

system("cat FILENAME | perl -e 'while(<>) { $_ =~ s/XXX/YYY/g; print $_;}'");

First command works fine but second command gives the following error:

syntax error at -e line 1, near "{ =~"
syntax error at -e line 1, near ";}"
Execution of -e aborted due to compilation errors.


Any idea why? Smilie

- Jingi
# 2  
Old 03-22-2007
It works for me.
Code:
$ cat file1
line1
line2 XXX
line3
$ cat x.c
#include <stdlib.h>
main()
{
        system("cat file1 | perl -e 'while(<>) { $_ =~ s/XXX/YYY/g; print $_;}'");
        exit(0);
}
$ gcc x.c -o x
$ ./x
line1
line2 YYY
line3
$

# 3  
Old 03-23-2007
when i put that system statement in a perl script, it gave those errors.
then this worked:
Code:
system ("cat FILENAME | perl -e 'while(<>) { s/XXX/YYY/g; print $_;}'");

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl and file and cat

Hi All i need a little script that can open a file , read it and then spit out some information from it from the shell i would do cat /var/log/Xorg.0.log | grep pixel | sed 's/: 330.*//' | how can i do this nicley in perl thanks Adam (3 Replies)
Discussion started by: ab52
3 Replies

2. Programming

Substitute string using location (preferably perl).

I have a string like. ATATATATTATTATATTATATTATT I want to substitute the characters to "C" by using these locations 3 7 10 18 15 20 desired Output: ATCCCCCTTACCCCCCCCCCTTATT any clue will be great help. :wall: thanks in advance. (2 Replies)
Discussion started by: admax
2 Replies

3. Shell Programming and Scripting

Substitute Perl Script

I am having trouble with a part of my substitute script I am using. I have it look through a file and find an exact match and then if it finds that match in the 1 file it should run the following 1 liner on 3 different files. perl -pi -e 's/$CurrentName\s/$NewName/g' foo.cfg; The issue that is... (8 Replies)
Discussion started by: Takau
8 Replies

4. Shell Programming and Scripting

substitute variable for values in perl

hi all, how do i assign values passed in from command line to and sql statement in perl ?? e.g i want to assign :name1 and :Name2 to be whatever is passed into the perl script command line my $sqlStr = "select * from test_table where column1 = upper(nvl(:name1, name1 )) and column2... (1 Reply)
Discussion started by: cesarNZ
1 Replies

5. Shell Programming and Scripting

Perl: substitute multiple lines

I'd like to do this using Perl command line (sorry no awk, sed, etc.) replace the 3 middle lines in a file by one line: aaa 123 bbb 234 ccc 34567 dd 4567 ee 567 to: aaa 123 AAA ee 567 I tried this but not working: perl -pi -e "s/aaa\ 123\nbbb\ 234\nccc\ 34567/AAA/" file (2 Replies)
Discussion started by: tintin78899
2 Replies

6. Shell Programming and Scripting

problem using CAT command in PERL

Hi All, I was trying to run the cat command using perl SCRIPT for my daily reports. However cat command is not working in PERL. please help me. cat FILE1.txt |cut -d "|" -f1 >INPUT1.txt cat FILE2.txt|wc -l *9111*|>INPUT2.txt paste INPUT1,INPUT2 >OUTPUT.txt Thanks in advance ... (3 Replies)
Discussion started by: adaleru
3 Replies

7. Shell Programming and Scripting

Formatting problem with cat, egrep and perl

Hi guys I'm using the following script to change input file format to another format. some where I'm getting the error. Could you please let me know if you find out? cat input.txt|egrep -v ‘^#'|\ perl -ane ‘if (@F>3){$_=~/(chr.+):(\d+)\ s()/;print $1,”\t”,$2,”\t”,($2+35),”\n”}'\ > output.bed ... (1 Reply)
Discussion started by: repinementer
1 Replies

8. Shell Programming and Scripting

How to substitute the value with in double quotes in perl?

Hi, I have string like this: $str=' DNA OR ("rna AND binding AND protein")'; I just wanted to substitute AND with a blank. How can i do that? I want the output like this: $string= DNA OR ("rna binding protein") (3 Replies)
Discussion started by: vanitham
3 Replies

9. Shell Programming and Scripting

How to substitute brackets in the beginning of string in perl?

Hi, I have a string like this user can specify different query sets that is why "or" is mentioned: $string="]("; or $string="](("; or $string="]((("; or $string="]((((("; (1 Reply)
Discussion started by: vanitham
1 Replies

10. UNIX for Dummies Questions & Answers

how to write perl substitute command in shell scripts

How to write perl substitute command in shell script without invoking a perl script file seperately. for ex: shell script to relace IT with CSC in a file using perl substitute command. (3 Replies)
Discussion started by: param_it
3 Replies
Login or Register to Ask a Question