1753960 Members
7363 Online
108811 Solutions
New Discussion юеВ

Modify file

 
SOLVED
Go to solution
Allanm
Super Advisor

Modify file

I have an html file like the following and I need to remove the leading line numbers from it to have just the html file with me. Can you tell me the way to remove those through sed and perl or something better.

Thanks,
Allan

First CGI Form


1


2 Please enter your name:

3


Please enter your phone number:

4


5

6



5 REPLIES 5
Steven Schweda
Honored Contributor

Re: Modify file

Knowing practically nothing about what's in
the file, it's hard to guarantee that
anything simple won't corrupt the data, but
you could try something simple with "sed":

$ echo '127
$

man sed
TwoProc
Honored Contributor
Solution

Re: Modify file

sed -e "s/[0-9]* //" yourfilename > newfile

or

cat yourfilename | sed -e "s/[0-9]* //" > newfile

example 1 being a single change from a file,
and example 2 being the edit from a pipe stream.


We are the people our parents warned us about --Jimmy Buffett
Allanm
Super Advisor

Re: Modify file

Thanks John!
Steven Schweda
Honored Contributor

Re: Modify file

What? You needed someone to tell you to use
a pipe, too?


> [...] 's/^[0-9]*//'

Leaves the white space.

> "s/[0-9]* //"

Expects at least one space, and removes one.

's/^[0-9]*[ \t]*//'

(where "\t" may need to be a literal Tab
character)

Removes all white space (space and or tab
characters) after the number).

As usual, many things are possible.
TwoProc
Honored Contributor

Re: Modify file

Allan,

I just read Steve's posting, and his is more correct, in that he is making sure that the numbers you're pulling out are at the beginning of the line while my sed example does not.

What I put as:
sed -e "s/[0-9]* //"

Should be like Steve's example and read:
sed -e "s/^[0-9]* //"

That carat symbol "^" tells that sed command to find a numeric sequence at the start of a line, which is more correct to what you're needing. My suggested code from a few days back would remove the ones at the beginning of the line, but also in other places as well.

Please make sure to add the carat "^" symbol before the brace "[" character.

We are the people our parents warned us about --Jimmy Buffett