Mazdajai
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?
I tried to add "," but no luck. Any suggestion?
perl -F"," -lane "/Cluster1.+?Red Hat Enterprise Linux/ && print (@F[3],@F[4])" results.txt
What did you want that statement to do?
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.
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
or
perl -F"," -lane '/Cluster1.+?Red Hat Enterprise Linux/ && print "$F[3],$F[4]"' results.txt
ASKER
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 -
Sample input -
"abc","Cluster1","Red Hat Enterprise Linux","12345"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Your sample input only goes from $F[0] to $F[3]
Did you mean to print @F[2,3] ?
Did you mean to print @F[2,3] ?
ASKER
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?
It works!!!!!! How come this works but not when I use double quotes around it? Is this the only solution?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
tyvm