On 5/6/2008 5:03 AM, pk wrote:
> On Tuesday 6 May 2008 11:52, Nezhate wrote:
>
>
>>Hi guys,
>>I've a small script that takes some data from file and split each word
>>in characters. There is 1 word per line in file.
>>For example, file contains 2 words:
>>Linux
>>foo
>>
>>the result must be :
>>
>>L
>>i
>>n
>>u
>>x
>>f
>>o
>>o
>>
>>to do this I used the next command, but it fails
>>awk '{for (i=1;i<=NF;i++) {for (j=1;j<=length($i);j++) {print
>>$i[j] } } } }' read_text.txt
>
>
> Use an empty FS:
>
> awk -F '' '{for (i=1;i<=NF;i++) print $i}' read_text.txt
>
> Note that this needs GNU awk.
>
True, as does the solution I posted:
awk -v FS='' -v OFS='\n' '$1=$1' file
With other awks:
awk -v ORS= '{gsub(/./,"&\n")}1' file
Regards,
Ed.


|