awk - field separator change in program, letters in the field

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?

diego9403

Posted 2015-08-24T08:38:32.073

Reputation: 807

1Could 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 – 2015-08-24T09:23:00.467

I found solution couple minutes ago. I use "split()" function. – diego9403 – 2015-08-24T17:52:29.913

Answers

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

Erik Bryer

Posted 2015-08-24T08:38:32.073

Reputation: 21