Operating System - HP-UX
1748157 Members
4225 Online
108758 Solutions
New Discussion юеВ

Re: awk - single character field separator

 
SOLVED
Go to solution
harry d brown jr
Honored Contributor
Solution

Re: awk - single character field separator


Here you go:


echo hello | awk '{gsub("(.)","& " );print $1;}'


The POWER of regex's!!!


live free or die
harry d brown jr
Live Free or Die
harry d brown jr
Honored Contributor

Re: awk - single character field separator

or

echo hello | sed "s/\(.\)/& /g" | awk '{printf("f1(%s) f2(%s) f3(%s) f4(%s) f5(%s)\n",$1,$2,$3,$4,$5);}

f1(h) f2(e) f3(l) f4(l) f5(o)

or
echo hello | sed "s/\(.\)/& /g" | awk '{print $5,$4,$3,$2,$1;}'

o l l e h


live free or die
harry d brown jr
Live Free or Die
Mark Tunnell
Advisor

Re: awk - single character field separator

Wow! Thanks!
Vibhor Kumar Agarwal
Esteemed Contributor

Re: awk - single character field separator

Why to complicate
We can simply use:

echo hello | sed "s/./& /g" | awk '{print $5,$4,$3,$2,$1;}'

I know we can use any general os command in awk block, but somehow i am unable to figure out how.
Can someone help me start it out.

Thanks
Vibhor Kumar Agarwal
H.Merijn Brand (procura
Honored Contributor

Re: awk - single character field separator

lt09:/home/merijn 110 > echo hello | perl -lne'$,=" ";print split//'
h e l l o
lt09:/home/merijn 111 > echo hello | perl -lne'$,=" ";print reverse split//'
o l l e h
lt09:/home/merijn 112 >

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn