abk07
1
Hi! I'm trying to assign line numbers to each line of the file
for example consider the following..
The contents of the input file are
hello how are you?
I'm fine.
How about you?
I'm trying to get the following output..
1 hello how are you?
2 I'm fine.
3 How about you?
Note:The number has to be followed by a space not a tab..
Any idea of how to do it??
Thanks in advance..
Try
awk '{print NR" "$0}' input_file
getmmg
3
perl -lne 'print "$. $_" input
...or, the same in sed:
sed 's/^/= /' /path/to/infile > /path/to/outfile
I hope this helps.
bakunin
methyl
6
@itkamaraj
The separator in "cat -v" is a tab character.
$ nl -nln -s\ infile
If you need to reduce the default numwidth, use the -w option:
$ nl -nln -s\ -w2 infile
1 hello how are you?
2 I'm fine.
3 How about you?
i didnt notice the note section
Note:The number has to be followed by a space not a tab..
while read line ; do count=`expr $count + 1`; echo -n "$count "; echo $line; done < filename
while read line ; do count=`echo "$count + 1"|bc`; echo -n "$count "; echo $line; done < filename
abk07
9
Thank you for all your replies!