Re: OT: sed problem

2004-02-01 Thread greg
On Sun, 2004-02-01 at 13:52, Daniela wrote:
> On Sunday 01 February 2004 18:10, Chris Pressey wrote:
[... snip ...]
> >
> > Or you could avoid sh variables and do whatever processing you have to
> > do entirely in awk (or perl.)
> 
> I really like csh programming. Everyone says that csh is crap for scripting, 
> but it isn't. I think Perl is harder than csh.
> But let's not start another holy war.

I think shell scripting is great to. But what makes it so powerful is
the ability to use tools and executables from your path. That would
include tools like awk, sed, grep and perl.
-- 
greg <[EMAIL PROTECTED]>

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: OT: sed problem

2004-02-01 Thread Daniela
On Sunday 01 February 2004 18:10, Chris Pressey wrote:
> On Sun, 1 Feb 2004 15:33:58 +
>
> Daniela <[EMAIL PROTECTED]> wrote:
> > On Sunday 01 February 2004 01:34, Jez Hancock wrote:
> > > On Sun, Feb 01, 2004 at 01:38:44AM +, Daniela wrote:
> > > > I was wondering how I can do the following with sed (or another
> > > > program): 1. Output only the text from the start of the line to
> > > > the first pipe character 2. Output only the text between the last
> > > > and the previous pipe character Or, split the line at the pipe
> > > > characters and assign the parts to different shell variables.
> > >
> > > #!/bin/sh
> > > test="one|two|three"
> > > set `echo "$test" | sed -e 's/\|/ /g'`
> > >
> > > # $1="one", $2="two", $3="three":
> > > echo $@
> >
> > This doesn't work when the parts between the pipe characters contain
> > spaces themselves.
>
> Nor does the awk approach I posted, incidentally - the problem being
> that sh likes to split up its input into variables, by spaces.

awk -F'|' '{ print $1 }'  does work indeed. This way, I can assign the parts 
to different variables, and dismiss the parts I don't need.

> You can work around it by translating the spaces into some unused
> character first, then translating pipes to spaces, then finally
> translating the unused characters back into spaces in each of the
> variables.
>
> There may be a simpler way, but if so, I don't know what it is.
>
> Or you could avoid sh variables and do whatever processing you have to
> do entirely in awk (or perl.)

I really like csh programming. Everyone says that csh is crap for scripting, 
but it isn't. I think Perl is harder than csh.
But let's not start another holy war.


___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: OT: sed problem

2004-02-01 Thread Chris Pressey
On Sun, 1 Feb 2004 15:33:58 +
Daniela <[EMAIL PROTECTED]> wrote:

> On Sunday 01 February 2004 01:34, Jez Hancock wrote:
> > On Sun, Feb 01, 2004 at 01:38:44AM +, Daniela wrote:
> > > I was wondering how I can do the following with sed (or another
> > > program): 1. Output only the text from the start of the line to
> > > the first pipe character 2. Output only the text between the last
> > > and the previous pipe character Or, split the line at the pipe
> > > characters and assign the parts to different shell variables.
> >
> > #!/bin/sh
> > test="one|two|three"
> > set `echo "$test" | sed -e 's/\|/ /g'`
> >
> > # $1="one", $2="two", $3="three":
> > echo $@
> 
> This doesn't work when the parts between the pipe characters contain
> spaces themselves.

Nor does the awk approach I posted, incidentally - the problem being
that sh likes to split up its input into variables, by spaces.

You can work around it by translating the spaces into some unused
character first, then translating pipes to spaces, then finally
translating the unused characters back into spaces in each of the
variables.

There may be a simpler way, but if so, I don't know what it is.

Or you could avoid sh variables and do whatever processing you have to
do entirely in awk (or perl.)

-Chris
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: OT: sed problem

2004-02-01 Thread Marty Landman
At 10:30 AM 2/1/2004, Daniela wrote:

Looks fine, but does Perl support multi-dimensional arrays?
Yes.

Marty Landman   Face 2 Interface Inc 845-679-9387
This Month's New Quiz --- Past Superbowl Winners
Make a Website: http://face2interface.com/Home/Demo.shtml
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: OT: sed problem

2004-02-01 Thread Daniela
On Sunday 01 February 2004 01:34, Jez Hancock wrote:
> On Sun, Feb 01, 2004 at 01:38:44AM +, Daniela wrote:
> > I was wondering how I can do the following with sed (or another program):
> > 1. Output only the text from the start of the line to the first pipe
> > character 2. Output only the text between the last and the previous pipe
> > character Or, split the line at the pipe characters and assign the parts
> > to different shell variables.
>
> #!/bin/sh
> test="one|two|three"
> set `echo "$test" | sed -e 's/\|/ /g'`
>
> # $1="one", $2="two", $3="three":
> echo $@

This doesn't work when the parts between the pipe characters contain spaces 
themselves.


___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: OT: sed problem

2004-02-01 Thread Daniela
On Sunday 01 February 2004 01:27, Robert Barten wrote:
> On Sun, Feb 01, 2004 at 01:38:44AM +, Daniela wrote:
> > I was wondering how I can do the following with sed (or another program):
> > 1. Output only the text from the start of the line to the first pipe
> > character 2. Output only the text between the last and the previous pipe
> > character Or, split the line at the pipe characters and assign the parts
> > to different shell variables.
>
> cat file | awk -F '|' '{print $1}'
>
> you may print $2 $3 $4 ... or NF (number of fields)

Great, thanks.


___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: OT: sed problem

2004-02-01 Thread Daniela
On Sunday 01 February 2004 00:58, Marty Landman wrote:
> At 08:38 PM 1/31/2004, Daniela wrote:
> >I was wondering how I can do the following with sed (or another program):
>
> How's Perl, Daniela?
>
> >1. Output only the text from the start of the line to the first pipe
> > character
>
> $out = ($line =~ /^([^\|]+)/);
>
> >2. Output only the text between the last and the previous pipe character
>
> $out = ($line =~ /\|([^\|]+)|/);
>
> >Or, split the line at the pipe characters and assign the parts to
> >different shell variables.
>
> my @ary = split '|', $line;

Looks fine, but does Perl support multi-dimensional arrays?


> These are untested but probably pretty close at least. Sorry, I haven't
> gotten to shell scripting yet so I think in terms of Perl.
>
> Marty Landman   Face 2 Interface Inc 845-679-9387
> This Month's New Quiz --- Past Superbowl Winners
> Make a Website: http://face2interface.com/Home/Demo.shtml

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: OT: sed problem

2004-01-31 Thread Jez Hancock
On Sun, Feb 01, 2004 at 01:38:44AM +, Daniela wrote:
> I was wondering how I can do the following with sed (or another program):
> 1. Output only the text from the start of the line to the first pipe character
> 2. Output only the text between the last and the previous pipe character
> Or, split the line at the pipe characters and assign the parts to different 
> shell variables.

#!/bin/sh
test="one|two|three"
set `echo "$test" | sed -e 's/\|/ /g'`

# $1="one", $2="two", $3="three":
echo $@


-- 
Jez Hancock
 - System Administrator / PHP Developer

http://munk.nu/
http://jez.hancock-family.com/  - Another FreeBSD Diary
http://ipfwstats.sf.net/- ipfw peruser traffic logging
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: OT: sed problem

2004-01-31 Thread Robert Barten
On Sun, Feb 01, 2004 at 01:38:44AM +, Daniela wrote:
> I was wondering how I can do the following with sed (or another program):
> 1. Output only the text from the start of the line to the first pipe character
> 2. Output only the text between the last and the previous pipe character
> Or, split the line at the pipe characters and assign the parts to different 
> shell variables.

cat file | awk -F '|' '{print $1}'

you may print $2 $3 $4 ... or NF (number of fields)
-- 
Robert Barten
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: OT: sed problem

2004-01-31 Thread Chris Pressey
On Sun, 1 Feb 2004 01:38:44 +
Daniela <[EMAIL PROTECTED]> wrote:

> I was wondering how I can do the following with sed (or another
> program): 1. Output only the text from the start of the line to the
> first pipe character 2. Output only the text between the last and the
> previous pipe character Or, split the line at the pipe characters and
> assign the parts to different shell variables.

It sounds like awk might be better suited to what you want to do than
sed.

You should be able to do something like this with sh and awk:

cat test.txt | awk -F'|' '{ print $1,$2,$3 }' | \
while read VAR1 VAR2 VAR3; do
   # do something with $VAR1, $VAR2, and $VAR3
done

So if test.txt contains

a|b|c
d|e|f

On the first iteration of the while loop, VAR1=a, VAR2=b, and VAR3=c,
and on the second iteration... well, you get the idea :)

-Chris
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: OT: sed problem

2004-01-31 Thread Marty Landman
At 08:38 PM 1/31/2004, Daniela wrote:
I was wondering how I can do the following with sed (or another program):
How's Perl, Daniela?

1. Output only the text from the start of the line to the first pipe character
$out = ($line =~ /^([^\|]+)/);

2. Output only the text between the last and the previous pipe character
$out = ($line =~ /\|([^\|]+)|/);

Or, split the line at the pipe characters and assign the parts to 
different shell variables.
my @ary = split '|', $line;

These are untested but probably pretty close at least. Sorry, I haven't 
gotten to shell scripting yet so I think in terms of Perl.

Marty Landman   Face 2 Interface Inc 845-679-9387
This Month's New Quiz --- Past Superbowl Winners
Make a Website: http://face2interface.com/Home/Demo.shtml
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"