Link to home
Start Free TrialLog in
Avatar of Mazdajai
MazdajaiFlag for United States of America

asked on

perl as awk with field seperator

I am writing perl / awk statement with field separators.

I tried to add "," but no luck. Any suggestion?

perl -F"," -lane "/Cluster1.+?Red Hat Enterprise Linux/ && print (@F[3],@F[4])" results.txt

Open in new window

Avatar of ozo
ozo
Flag of United States of America image

What did you want that statement to do?
Avatar of Mazdajai

ASKER

To add a comma between @F[#]...
My expected output :
ABC,ABC...
current output:
ABCABC
in awk I can do 'print $1","$2...' but I am having a rough time getting it work in perl.
perl -F"," -lane '$"=",";/Cluster1.+?Red Hat Enterprise Linux/ && print "@F[3,4]"' results.txt
or
perl -F"," -lane '/Cluster1.+?Red Hat Enterprise Linux/ && print "$F[3],$F[4]"' results.txt
Same result. The second statement works in Linux but not Windows. I was having weird issue with GNU awk in Windows with comma. That why I go and try perl...

Sample input -
"abc","Cluster1","Red Hat Enterprise Linux","12345"

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Your sample input only goes from $F[0] to $F[3]
Did you mean to print @F[2,3] ?
It is a partial input, the full input is up to $F[13].

It works!!!!!! How come this works but not when I use double quotes around it? Is this the only solution?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
tyvm