0

I want to change FS in awk, but not in BEGIN. I want to print word and the letter.

awk 'BEGIN{FS=""}{print $1; FS=" ";print $1; FS=""}'

Of course it does't work. Is there any function, way to show words's letters?

2
  • 1
    Could you give a sample input and desired output? What exactly are you trying to do? Would multiple field separators do the job? What should an empty FS do?
    – FelixJN
    Aug 24, 2015 at 9:23
  • I found solution couple minutes ago. I use "split()" function.
    – diego9403
    Aug 24, 2015 at 17:52

1 Answer 1

0

awk is record oriented. It won't allow resetting the FS while processing the same line. Judging from the code you've written, you would like to take, e.g., this input:

First  
Second

and you would want to see as output:

F
First  
S
Second

One way to do that with awk:

awk '{print substr($1,1,1) ; print $1}' inputfile
F
First
S
Second

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .