1834817 Members
3358 Online
110070 Solutions
New Discussion

line numbering

 
SOLVED
Go to solution
Ian McClement
Occasional Contributor

line numbering

Thanks Dan, format is like:
1 kfhgvhgv kfjkhfhb
2 if kfjn
3 vkjnfkjvnjnk
4 lkjkfjh
.......
99 for each in
100 do
101 jgkjghk jghjjg ljfdhk;
102 done
.......
999 if adflkjh
1000 afjhkjfh
1001 kfjvhkdlfh

etc.

I have tried cut from 2nd field on but loses formatting.
Any suggestions greatly appreciated.

Ian
3 REPLIES 3
RikTytgat
Honored Contributor
Solution

Re: line numbering

Hi,

Try this:
cat file | sed -e 's/^[[:digit:]]\{1,\}[[:space:]]\(.*\)$/\1/'

This even keeps indentation after the numbers.

Bye,
Rik.
Sandor Horvath_2
Valued Contributor

Re: line numbering

Hi !

What is mean 2nd field ?

real 2nd >
.. | awk ' { print $2 } '

or cut number >
.. | awk ' { print sustr($0,index($0," ")+1)}'

regards, Saa
If no problem, don't fixed it.
Dan Hetzel
Honored Contributor

Re: line numbering

Hi Ian,

sed 's/^[[:digit:]]*//' < from_file > to_file
should work as you want. It simply supresses all digits at the beginning of every line.

Best regards,

Dan

PS: As you're new in this forum, simply click on the button if you want to add some comments. Don't start a new thread as users would loose track. ;-)
Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com