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?

  • 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? – Fiximan Aug 24 '15 at 9:23
  • I found solution couple minutes ago. I use "split()" function. – diego9403 Aug 24 '15 at 17:52
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.