gawk to perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting gawk to perl
# 1  
Old 06-29-2009
gawk to perl

Hi all


I’m looking for a perl equivalent to this command string
I need to imbed this in a existing perl script

Code:
cat file1 | gawk -F"|" '{print $1","$2,",",$3,",",$11 >> "new-file"}'


Thank you

Last edited by Yogesh Sawant; 06-30-2009 at 03:40 AM.. Reason: added code tags
# 2  
Old 06-29-2009
I thought you found the solution?

https://www.unix.com/shell-programmin...#post302329767
# 3  
Old 06-29-2009
gawk should work inside perl i guess...
# 4  
Old 06-30-2009
Try a2p (awk to perl)...
Code:
$ echo 'BEGIN{FS="|";OFS=","}{print $1,$2,$3,$11 >> "new-file"}'| a2p

..gives this (after some minor edits)...
Code:
#!/usr/bin/perl

open(NEW_FILE, '>>new-file') || die 'Cannot create file "new-file".';

$\ = "\n";             
$FS = '|';
$, = ',';

while (<>) {
    ($Fld1,$Fld2,$Fld3,$Fld4,$Fld5,$Fld6,$Fld7,$Fld8,$Fld9,$Fld10,$Fld11) = split(/[|\n]/, $_, -1);
    print NEW_FILE $Fld1, $Fld2, $Fld3, $Fld11;
}

# 5  
Old 06-30-2009
Thank you all for the answers I think I got it right this time
I say this time because it thought I had it right a while back
From a previous post.

When everything is clean I will post the script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Gawk command

Hello experts :) I have a question about Gawk command on AIX, could someone tell me the function of this command ? i have a script which has a gawk command : /usr/bin/xmllint --format /data/work/PROU/aggregates.flat.xml | gawk '! /<!--.*-->/ {print $0}' | gawk -f... (3 Replies)
Discussion started by: rimob
3 Replies

2. SCO

Need help with gawk

I am trying to use gawk to search a file and put the second value of the string into a string. gawk -F: '$1~/CXFR/ {print $2}' go.dat Below is the file 'go.dat' ==================== HOME :/ CTMP :/tmp CUTL :/u/rdiiulio/bin CWRK :/u/work CXFR :/u/xfer ... (1 Reply)
Discussion started by: trolley
1 Replies

3. Shell Programming and Scripting

gawk: not found

While running gawk, OS stating that command not found. (5 Replies)
Discussion started by: sbaisakh
5 Replies

4. Shell Programming and Scripting

Doubt with gawk

Hi All, I have a doubt with gawk. I have a shell script "cleanup" which calls a gawk script "cleanawk" in it. we have two unix servers epsun532 and wpsun712. So i tested the script in both the environments. In epsun532 while calling the gawk script i just mentioned something like this ... (1 Reply)
Discussion started by: Diddy
1 Replies

5. Shell Programming and Scripting

Help with gawk command

Hi, I have a situation. in a particular file , from the 9th column i have to match a particular pattern . i want a second file which is made by excluding them. I wrote a code like this. gawk '$9~/^(SPI|OTC|SAX)$/' /home/ceh1/ceh_prod/plx_"$mydate"_old.tsv >>... (1 Reply)
Discussion started by: pranabrana
1 Replies

6. Windows & DOS: Issues & Discussions

Cannot run command line scripts in perl or gawk

I originally posted this to a different forum (I am a new Perl user) and realized the error so I will ask here. I am on a WindowsXP machine trying to run perl and gawk scripts from the command line. I have perl and gawk installed and environment set to C:\perl\bin and cannot get a script to... (2 Replies)
Discussion started by: 10000springs
2 Replies

7. Shell Programming and Scripting

Gawk Help

Hi, I am using the script to print the portion of the file containing a particular string. But it is giving error "For Reading (No such file or directory). I am using cygwin as unix simulator. cat TT35*.log | gawk -v search="12345678" ' /mSOriginating /,/disconnectingParty/ { ... (1 Reply)
Discussion started by: vanand420
1 Replies

8. UNIX for Dummies Questions & Answers

should I start with cgi and perl? gawk? help!

Hi all, I must create a web page but I have no idea (yet) of writing html or php, so right now I'm lost in a bunch of acronyms and languages, and I don't know which one should I start to learn... so please, could you give me a recommendation? The visitor to my web page should select an... (2 Replies)
Discussion started by: Kronos
2 Replies

9. Shell Programming and Scripting

gawk will work or not ?

Hai I am using bash-2.03$ bash --version GNU bash, version 2.03.0(1)-release (sparc-sun-solaris) I am not able to use gawk command its showing command not found , why ? Eg: awk 'NR==1' fix.txt | gawk 'BEGIN { FIELDWIDTHS = "3 2" } { printf($1"|"$2); }'... (3 Replies)
Discussion started by: tkbharani
3 Replies

10. Shell Programming and Scripting

gawk HELP

I have to compare records in two files. It can be done using gawk/awk but i am unable to do it. Please help me File1 ABAAAAAB BC asa sa ABAAABAA BC bsa sm ABBBBAAA BC bxz sa ABAAABAB BC csa sa ABAAAAAA BC dsa sm ABBBBAAB BC dxz sa File 2 ABAAAAAB BC aas ba ABAAAAAB BC asa sa... (6 Replies)
Discussion started by: sandeep_hi
6 Replies
Login or Register to Ask a Question