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

LVL 21
MazdajaiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
What did you want that statement to do?
0
MazdajaiAuthor Commented:
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.
0
ozoCommented:
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
0
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

MazdajaiAuthor Commented:
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

0
ozoCommented:
In Windows

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ozoCommented:
Your sample input only goes from $F[0] to $F[3]
Did you mean to print @F[2,3] ?
0
MazdajaiAuthor Commented:
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?
0
ozoCommented:
Dos shell under windows uses " instead of ', making it awkward to include " in the script.
Not remembering how to do it, and not being at a machine where I could test it at the time, it was easier for me to rewrite the Perl script to avoid using "
0
MazdajaiAuthor Commented:
tyvm
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.