Use two delimiters in awk

I have a file having lines like:

14: <a="b" val="c"/>
18: <a="x" val="d"/>
54: <a="b" val="c"/>
58: <a="x" val="e"/>

I need to create a file with output:
14
d
54
e

So basically, for every odd line I need 1st word if delimiter is ':' and for every even line I need 4th word if delimiter is "
........

Any help plz.....

awk -F\" 'NR%2{sub (":.*","",$1);print $1;next}{print $4}' file

Thanks a lot.. Its working in bash but not in ksh.

Try:

awk -F'"' 'NR%2{sub (":.*","",$1);print $1;next}{print $4}' file

I mean when run in cygwin, it works but when uploaded in unix server, it giving an error of "bailing out"

What is the full error message you are receiving?

I tried: awk -F'"' 'NR%2{sub (":.*","",$1);print $1;next}{print $4}' file
but its giving same error...

---------- Post updated at 03:02 PM ---------- Previous update was at 03:02 PM ----------

awk: syntax error near line 1
awk: bailing out near line 1

Are you on Solaris?

no... unix......

What kind of Unix? AIX? HP-UX? What does uname -a say?

SunOS asdo0002 5.10 Generic_144488-12 sun4us sparc FJSV,GPUSC-M

So you ARE on Solaris (SunOS 5.10 = Solaris). Try this:

nawk -F'"' 'NR%2{sub (":.*","",$1);print $1;next}{print $4}' file
1 Like

Thanks.. it worked....
I have one more question....

Line from input file
a : b : c " d " e " f : g : h " i " j " k " l

output
k b a

so its taking 8th word if " is the delimiter, 2nd and 1st word if : is the delimiter and returning all in one line....

Thanks.....

nawk -F"[:\"]" '{gsub(" ","");print $11,$2,$1}' file
1 Like

Thanks a lot... I really appreciate........
I am new to shell script. Can you briefly name a good book on the same for starter..