From: Mike Jones on


I have a long file with more lines than I fancy manually editing, and
need to cut all the added comments from any lines that have them.

ie:

line1
line2 # comments
line3
line4 # with notes
line5 # more stuff

....becomes

line1
line2
line3
line4
line5

Anybody got quick'n'simple technique for this kind of thing?



XP alt.os.linux,alt.os.linux.slackware
FU alt.os.linux

--
*=( http://www.thedailymash.co.uk/
*=( For all your UK news needs.
From: J.O. Aho on
Mike Jones wrote:
>
>
> I have a long file with more lines than I fancy manually editing, and
> need to cut all the added comments from any lines that have them.
>
> ie:
>
> line1
> line2 # comments
> line3
> line4 # with notes
> line5 # more stuff
>
> ...becomes
>
> line1
> line2
> line3
> line4
> line5
>
> Anybody got quick'n'simple technique for this kind of thing?

Something like:

sed 's/\([a-zA-Z0-9]*\)#.*/\1/g' -i file

don't forget to make a backup before you test.


--

//Aho
From: ray on
On Mon, 02 Aug 2010 23:24:21 +0000, Mike Jones wrote:

> I have a long file with more lines than I fancy manually editing, and
> need to cut all the added comments from any lines that have them.
>
> ie:
>
> line1
> line2 # comments
> line3
> line4 # with notes
> line5 # more stuff
>
> ...becomes
>
> line1
> line2
> line3
> line4
> line5
>
> Anybody got quick'n'simple technique for this kind of thing?
>
>
>
> XP alt.os.linux,alt.os.linux.slackware FU alt.os.linux

'cut' should work quite nicely.
From: stuart on
Mike Jones wrote:
>
> I have a long file with more lines than I fancy manually editing, and
> need to cut all the added comments from any lines that have them.
>
> ie:
>
> line1
> line2 # comments
> line3
> line4 # with notes
> line5 # more stuff
>
> ...becomes
>
> line1
> line2
> line3
> line4
> line5
>
> Anybody got quick'n'simple technique for this kind of thing?


Load the file into vi and do command

:%s/#.*\n/^M/g

and all those comments disappear.

I get that ^M by doing Ctrl+v Ctrl+m

Stuart
From: Martin on
On 08/03/2010 12:24 AM, Mike Jones wrote:
> line1
> line2 # comments
> line3
> line4 # with notes
> line5 # more stuff
>
> ...becomes
>
> line1
> line2
> line3
> line4
> line5

Try the following. That is assuming that your comments # is the first #
on each line:

sed -e 's/\(.*[^#]\)\(#.*\)/\1/' file.txt

regards
Martin