Operating System - HP-UX
1834186 Members
2810 Online
110064 Solutions
New Discussion

Re: ksh help: wanted to add sequential numbers at end of each word

 
SOLVED
Go to solution
Hanry Zhou
Super Advisor

ksh help: wanted to add sequential numbers at end of each word

I have a file, and there are list of words in it, and each word occupies one line:



Now, I want to add a sequential number at the end of each word(line). Please help me out how do I achive that? Appreciate your help!

aaa 100
bbb 101
ccc 102
ddd 103
....


none
4 REPLIES 4
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: ksh help: wanted to add sequential numbers at end of each word

#!/usr/bin/ksh

typeset -i N=100
cat myfile | while read F
do
echo "${F} ${N}"
((N += 1))
done
exit 0
If it ain't broke, I can fix that.
spex
Honored Contributor

Re: ksh help: wanted to add sequential numbers at end of each word

Hi Hanry,

$ awk -v i=100 '{print($0,i); i+=1}'
PCS
Sandman!
Honored Contributor

Re: ksh help: wanted to add sequential numbers at end of each word

Try the awk construct below:

# awk 'BEGIN{i=100}{print $0,i++}' infile

~cheers
Dennis Handly
Acclaimed Contributor

Re: ksh help: wanted to add sequential numbers at end of each word

If you want to number on the left, there is nl(1).