From: Eef Hartman on
In alt.os.linux.slackware Mike Jones <luck(a)dasteem.invalid> 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?

A job for sed:
sed "s/#.*//" file > newfile
or if you want the spaces before the # also removed
sed "S/ *#.*//" file > newfile

Note: "newfile" MUST be a different filename then the inputfile,
otherwise the inputfile gets zero'd before being opened.
It is possible to edit the file directly in-place with the option
--in-place=bak
then the original file will be backup'ed first and then edited
in-place, so then the output redirection isn't needed.
--
******************************************************************
** Eef Hartman, Delft University of Technology, dept. SSC/ICT **
** e-mail: E.J.M.Hartman(a)tudelft.nl - phone: +31-15-27 82525 **
******************************************************************
From: Mike Jones on
Responding to stuart:

> 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


Sorry. Vi is not a text editor.

Its Project MK-Ultra mind-warping technology. %)

--
*=( http://www.thedailymash.co.uk/
*=( For all your UK news needs.
From: Mike Jones on
Responding to Eef Hartman:

> In alt.os.linux.slackware Mike Jones <luck(a)dasteem.invalid> 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?
>
> A job for sed:
> sed "s/#.*//" file > newfile
> or if you want the spaces before the # also removed
> sed "S/ *#.*//" file > newfile
>
> Note: "newfile" MUST be a different filename then the inputfile,
> otherwise the inputfile gets zero'd before being opened. It is possible
> to edit the file directly in-place with the option
> --in-place=bak
> then the original file will be backup'ed first and then edited in-place,
> so then the output redirection isn't needed.


sed: -e expression #1, char 1: unknown command: `S'

....plus blank newfile Oops!


--
*=( http://www.thedailymash.co.uk/
*=( For all your UK news needs.
From: Mike Jones on
Responding to Mike Jones:

> 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?
>
>


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

....from J.O. Aho did the trick.

Cheers guys!



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

--
*=( http://www.thedailymash.co.uk/
*=( For all your UK news needs.
From: Mike Jones on
Responding to J.O. Aho:

> 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.


Worked a treat. Cheers!

--
*=( http://www.thedailymash.co.uk/
*=( For all your UK news needs.