From: Eef Hartman on
Mike Jones <luck(a)dasteem.invalid> wrote:
> sed: -e expression #1, char 1: unknown command: `S'
>
> ...plus blank newfile Oops!

Oops indeed, the second command should also have been a lower-case s
(like the first). The difference is the " *" to catch spaces before
the # mark.
--
******************************************************************
** Eef Hartman, Delft University of Technology, dept. SSC/ICT **
** e-mail: E.J.M.Hartman(a)tudelft.nl - phone: +31-15-27 82525 **
******************************************************************
From: Loki Harfagr on
Tue, 03 Aug 2010 09:20:38 +0000, Mike Jones did cat :

> 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

note that the 'g' is not necessary:
$ sed -i 's/\([^#][^#]*\)#.*$/\1/' file

now, as you wished a "quick'n'simple technique", a
shorter form (rev logic) could be:
$ sed -i 's/#[^#]*$//' file
From: Mike Jones on
Responding to Loki Harfagr:

> Tue, 03 Aug 2010 09:20:38 +0000, Mike Jones did cat :
>
>> 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
>
> note that the 'g' is not necessary:
> $ sed -i 's/\([^#][^#]*\)#.*$/\1/' file
>
> now, as you wished a "quick'n'simple technique", a shorter form (rev
> logic) could be:
> $ sed -i 's/#[^#]*$//' file


I'll give it a test later. Cheers!

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

> Mike Jones <luck(a)dasteem.invalid> wrote:
>> sed: -e expression #1, char 1: unknown command: `S'
>>
>> ...plus blank newfile Oops!
>
> Oops indeed, the second command should also have been a lower-case s
> (like the first). The difference is the " *" to catch spaces before the
> # mark.


So,

sed "s/ *#.*//" file > newfile

?

--
*=( http://www.thedailymash.co.uk/
*=( For all your UK news needs.
From: Grant on
On Tue, 3 Aug 2010 15:38:29 +0000 (UTC), Mike Jones <luck(a)dasteem.invalid> wrote:

>Responding to Loki Harfagr:
>
>> Tue, 03 Aug 2010 09:20:38 +0000, Mike Jones did cat :
>>
>>> 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
>>
>> note that the 'g' is not necessary:
>> $ sed -i 's/\([^#][^#]*\)#.*$/\1/' file
>>
>> now, as you wished a "quick'n'simple technique", a shorter form (rev
>> logic) could be:
>> $ sed -i 's/#[^#]*$//' file
>
>
>I'll give it a test later. Cheers!

Gotta be careful when Loki plays golf. . . Fore!

Grant.