Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: split word ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 5 Topic 2230 of 2236
Post > Topic >>

Re: split word in characters

by Ed Morton <morton@[EMAIL PROTECTED] > May 6, 2008 at 05:34 AM

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.




 5 Posts in Topic:
split word in characters
Nezhate <mazouz.nezhat  2008-05-06 02:52:55 
Re: split word in characters
Ed Morton <morton@[EMA  2008-05-06 05:00:25 
Re: split word in characters
pk <pk@[EMAIL PROTECTE  2008-05-06 12:03:42 
Re: split word in characters
Ed Morton <morton@[EMA  2008-05-06 05:34:04 
Re: split word in characters
Nezhate <mazouz.nezhat  2008-05-06 03:38:11 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu May 15 21:14:52 CDT 2008.