[nylug-talk] need sed help
jh
jhlists at hirschman.net
Tue Apr 3 12:59:59 EDT 2007
Eric Moore wrote:
> jh <jhlists at hirschman.net> writes:
> First odd, when you have a question like this, it helps to tell us
> what doesn't work about it, like "it deletes all leading whitespace,
> not just the first line". This will help us diagnose your problem.
>
> The numerical flags to the s command mean the n'th instance on a given
> line (or more accurately, per pattern space, but that's almost always
> a line).
>
> So if we have this file:
> nyarlothotep:~$ cat baz
> foo bar blech
> baz quux
>
> We can delete the first bit of whitespace with:
>
> nyarlothotep:~$ sed -e 's/ \+//1' baz
> foo bar blech
> baz quux
>
> or the second with:
>
> nyarlothotep:~$ sed -e 's/ \+//2' baz
> foobar blech
> bazquux
>
> So what your command: -e 's/^[:space]*//1' does is replace the first
> instance of 0 or more space characters at the beginning of a line on
> each line (which is somewhat redundant, because there can't be a
> second instance of space at the beginning of a line).
>
> What you really want is to use an address range:
> nyarlothotep:~$ sed -e '1s/^ \+//' baz
> foo bar blech
> baz quux
>
Yes, I should have mentioned the symptom first.
The problem was that none of the white space in the first line (spaces
and tabs) got stripped out. Thanks for the response.
jh
More information about the nylug-talk
mailing list