Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parsing a word into characters

Status
Not open for further replies.

danstrobridge

Technical User
Oct 31, 2005
7
US
I am processing a file that has several fields separated by tabs. At one point in my workflow, I need to parse each each character in the first field so that I can I write the character to a new file along with some other information. The "other information" is what I have been able to figure out for myself... along with how print only the first field to that new file. What I am having a problem with is how to parse the content of the first field into its different characters.

For example, the input file might be:

one xxxxxx yyyyyyy zzzzzzz
two xxxxxx yyyyyyy zzzzzzz

the first of these four fields is really all i need.... and i need to write to a new file with the format:

o 11111111 2222222 one
n 33333333 4444444 one
e 55555555 6666666 one
t 77777777 8888888 two
w 99999999 10101010 two
o 11 11 11 12121212 two

i know how to pull in the last three fields in the above... if i only knew how to generate the 1st field from the input file.

Any help would be GREATLY appreciated.

Dan


 
Code:
echo '123 456' | nawk '{for(i=1; i <=length($1); i++) print substr($1, i, 1), "foo", "bar"}'

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top