Help with Sed command
am 08.04.2008 23:20:51 von littlehelphere
I have a script that runs sed through a loop. Everything is working
properly except for situations where a username is found with another
name. For example I am looking to change the following -
foo: foo@null.com
to
foo: /dev/null
This works properly but the issue is any other name, such as the
ones below will also be changed . So for example
dofoo: dofoo@null.com
is changed to
dofoo: do/dev/null
and
pefoo: pefoo@null.com
is changed to
pefoo: pe/dev/null.
I need to pass an argument, etc so that on the entry for "foo" is
modified. Any help would be appreciated. Thanks.
dofoo: dofoo@null.com
pefoo: pefoo@null.com
foo: foo@null.com
Re: Help with Sed command
am 08.04.2008 23:27:32 von Bill Marcum
On 2008-04-08, littlehelphere@gmail.com wrote:
>
>
> I have a script that runs sed through a loop. Everything is working
> properly except for situations where a username is found with another
> name. For example I am looking to change the following -
> foo: foo@null.com
> to
> foo: /dev/null
> This works properly but the issue is any other name, such as the
> ones below will also be changed . So for example
> dofoo: dofoo@null.com
> is changed to
> dofoo: do/dev/null
> and
> pefoo: pefoo@null.com
> is changed to
> pefoo: pe/dev/null.
> I need to pass an argument, etc so that on the entry for "foo" is
> modified. Any help would be appreciated. Thanks.
>
> dofoo: dofoo@null.com
> pefoo: pefoo@null.com
> foo: foo@null.com
>
sed 's#^foo:.*#foo: /dev/null#'
Re: Help with Sed command
am 09.04.2008 01:24:44 von Ed Morton
On 4/8/2008 4:20 PM, littlehelphere@gmail.com wrote:
> I have a script that runs sed through a loop. Everything is working
> properly except for situations where a username is found with another
> name. For example I am looking to change the following -
> foo: foo@null.com
> to
> foo: /dev/null
> This works properly but the issue is any other name, such as the
> ones below will also be changed . So for example
> dofoo: dofoo@null.com
> is changed to
> dofoo: do/dev/null
> and
> pefoo: pefoo@null.com
> is changed to
> pefoo: pe/dev/null.
> I need to pass an argument, etc so that on the entry for "foo" is
> modified. Any help would be appreciated. Thanks.
>
> dofoo: dofoo@null.com
> pefoo: pefoo@null.com
> foo: foo@null.com
>
awk '$1=="foo:"{ $2="/dev/null/" }1' file
Ed.
Re: Help with Sed command
am 10.04.2008 16:09:17 von littlehelphere
On Apr 8, 5:27 pm, Bill Marcum wrote:
> On 2008-04-08, littlehelph...@gmail.com wrote:
>
>
>
> > I have a script that runs sed through a loop. Everything is working
> > properly except for situations where a username is found with another
> > name. For example I am looking to change the following -
> > foo: f...@null.com
> > to
> > foo: /dev/null
> > This works properly but the issue is any other name, such as the
> > ones below will also be changed . So for example
> > dofoo: do...@null.com
> > is changed to
> > dofoo: do/dev/null
> > and
> > pefoo: pe...@null.com
> > is changed to
> > pefoo: pe/dev/null.
> > I need to pass an argument, etc so that on the entry for "foo" is
> > modified. Any help would be appreciated. Thanks.
>
> > dofoo: do...@null.com
> > pefoo: pe...@null.com
> > foo: f...@null.com
>
> sed 's#^foo:.*#foo: /dev/null#'
I don't see how this is going to work. I may need to expand on what I
need to do. The sed command runs in a script with multiple names of
users. The file is runs against is a flat file and the syntax may
start with a comment in the first filed or may not (i.e - ngj or
#foongj). Either way I need a way to get only the specific user I
need modifie - in this case ngj. I tried the above and there was no
modifiction.
Re: Help with Sed command
am 10.04.2008 19:58:44 von Ed Morton
On 4/10/2008 9:09 AM, littlehelphere@gmail.com wrote:
> On Apr 8, 5:27 pm, Bill Marcum wrote:
>
>>On 2008-04-08, littlehelph...@gmail.com wrote:
>>
>>
>>
>>
>>>I have a script that runs sed through a loop. Everything is working
>>>properly except for situations where a username is found with another
>>>name. For example I am looking to change the following -
>>>foo: f...@null.com
>>>to
>>>foo: /dev/null
>>> This works properly but the issue is any other name, such as the
>>>ones below will also be changed . So for example
>>>dofoo: do...@null.com
>>>is changed to
>>>dofoo: do/dev/null
>>>and
>>>pefoo: pe...@null.com
>>>is changed to
>>>pefoo: pe/dev/null.
>>> I need to pass an argument, etc so that on the entry for "foo" is
>>>modified. Any help would be appreciated. Thanks.
>>
>>>dofoo: do...@null.com
>>>pefoo: pe...@null.com
>>>foo: f...@null.com
>>
>>sed 's#^foo:.*#foo: /dev/null#'
>
>
> I don't see how this is going to work. I may need to expand on what I
> need to do. The sed command runs in a script with multiple names of
> users. The file is runs against is a flat file and the syntax may
> start with a comment in the first filed or may not (i.e - ngj or
> #foongj). Either way I need a way to get only the specific user I
> need modifie - in this case ngj. I tried the above and there was no
> modifiction.
Then there's something about your input file you aren't telling us. Look:
$ cat file
foo: foo@null.com
#foo: foo@null.com
dofoo: dofoo@null.com
pefoo: pefoo@null.com
$ sed 's#^foo:.*#foo: /dev/null#' file
foo: /dev/null
#foo: foo@null.com
dofoo: dofoo@null.com
pefoo: pefoo@null.com
$ awk '$1=="foo:"{ $2="/dev/null/" }1' file
foo: /dev/null/
#foo: foo@null.com
dofoo: dofoo@null.com
pefoo: pefoo@null.com
If that's not what you want, please provide a clearer description of your
requirements along with some small set of sample input and the expected output
given that input.
Ed.
Re: Help with Sed command
am 11.04.2008 17:38:45 von littlehelphere
On Apr 10, 1:58 pm, Ed Morton wrote:
> On 4/10/2008 9:09 AM, littlehelph...@gmail.com wrote:
>
>
>
> > On Apr 8, 5:27 pm, Bill Marcum wrote:
>
> >>On 2008-04-08, littlehelph...@gmail.com wrote:
>
> >>>I have a script that runs sed through a loop. Everything is working
> >>>properly except for situations where a username is found with another
> >>>name. For example I am looking to change the following -
> >>>foo: f...@null.com
> >>>to
> >>>foo: /dev/null
> >>> This works properly but the issue is any other name, such as the
> >>>ones below will also be changed . So for example
> >>>dofoo: do...@null.com
> >>>is changed to
> >>>dofoo: do/dev/null
> >>>and
> >>>pefoo: pe...@null.com
> >>>is changed to
> >>>pefoo: pe/dev/null.
> >>> I need to pass an argument, etc so that on the entry for "foo" is
> >>>modified. Any help would be appreciated. Thanks.
>
> >>>dofoo: do...@null.com
> >>>pefoo: pe...@null.com
> >>>foo: f...@null.com
>
> >>sed 's#^foo:.*#foo: /dev/null#'
>
> > I don't see how this is going to work. I may need to expand on what I
> > need to do. The sed command runs in a script with multiple names of
> > users. The file is runs against is a flat file and the syntax may
> > start with a comment in the first filed or may not (i.e - ngj or
> > #foongj). Either way I need a way to get only the specific user I
> > need modifie - in this case ngj. I tried the above and there was no
> > modifiction.
>
> Then there's something about your input file you aren't telling us. Look:
>
> $ cat file
> foo: f...@null.com
> #foo: f...@null.com
> dofoo: do...@null.com
> pefoo: pe...@null.com
> $ sed 's#^foo:.*#foo: /dev/null#' file
> foo: /dev/null
> #foo: f...@null.com
> dofoo: do...@null.com
> pefoo: pe...@null.com
> $ awk '$1=="foo:"{ $2="/dev/null/" }1' file
> foo: /dev/null/
> #foo: f...@null.com
> dofoo: do...@null.com
> pefoo: pe...@null.com
>
> If that's not what you want, please provide a clearer description of your
> requirements along with some small set of sample input and the expected output
> given that input.
>
> Ed.
This seems to work, but how do I substitute the variable $i from the
loop for the user names being that this is a for i in ... loop.
Thanks.
Re: Help with Sed command
am 11.04.2008 18:07:48 von littlehelphere
On Apr 8, 7:24 pm, Ed Morton wrote:
> On 4/8/2008 4:20 PM, littlehelph...@gmail.com wrote:
>
>
>
> > I have a script that runs sed through a loop. Everything is working
> > properly except for situations where a username is found with another
> > name. For example I am looking to change the following -
> > foo: f...@null.com
> > to
> > foo: /dev/null
> > This works properly but the issue is any other name, such as the
> > ones below will also be changed . So for example
> > dofoo: do...@null.com
> > is changed to
> > dofoo: do/dev/null
> > and
> > pefoo: pe...@null.com
> > is changed to
> > pefoo: pe/dev/null.
> > I need to pass an argument, etc so that on the entry for "foo" is
> > modified. Any help would be appreciated. Thanks.
>
> > dofoo: do...@null.com
> > pefoo: pe...@null.com
> > foo: f...@null.com
>
> awk '$1=="foo:"{ $2="/dev/null/" }1' file
>
> Ed.
This does not seem work - I keep getting an error - also how do I
substitute the variable $i from the loop for the user names?
Re: Help with Sed command
am 11.04.2008 18:32:20 von Bill Marcum
On 2008-04-11, littlehelphere@gmail.com wrote:
>
>
> On Apr 8, 7:24 pm, Ed Morton wrote:
>>
>> awk '$1=="foo:"{ $2="/dev/null/" }1' file
>>
>> Ed.
>
> This does not seem work - I keep getting an error - also how do I
> substitute the variable $i from the loop for the user names?
If you are using Solaris, use nawk or /usr/xpg4/bin/awk. To use a
shell variable in awk, you can write:
nawk -v i="$i" '$1==i ":"{ $2="/dev/null/" }1' file
(Solaris experts: is there a difference between nawk and
/usr/xpg4/bin/awk, or is one a symlink to the other?)
Re: Help with Sed command
am 11.04.2008 21:58:15 von Ed Morton
On 4/11/2008 11:32 AM, Bill Marcum wrote:
> On 2008-04-11, littlehelphere@gmail.com wrote:
>
>>
>>On Apr 8, 7:24 pm, Ed Morton wrote:
>>
>>>awk '$1=="foo:"{ $2="/dev/null/" }1' file
>>>
>>> Ed.
>>
>>This does not seem work - I keep getting an error - also how do I
>>substitute the variable $i from the loop for the user names?
>
>
> If you are using Solaris, use nawk or /usr/xpg4/bin/awk. To use a
> shell variable in awk, you can write:
> nawk -v i="$i" '$1==i ":"{ $2="/dev/null/" }1' file
>
> (Solaris experts: is there a difference between nawk and
> /usr/xpg4/bin/awk, or is one a symlink to the other?)
They're different. /usr/xpg4/bin/awk is a POSIX awk (allegedly) while nawk isn't
so, for example, nawk doesn't support RE intervals:
$ echo "aaa" | nawk 'gsub(/a{2}/,"X")'
$ echo "aaa" | /usr/xpg4/bin/awk 'gsub(/a{2}/,"X")'
Xa
there are several other differences but both are still "modern" awks and so
behave generaly sanely, unlike /usr/bin/awk.
Regards,
Ed.