Unix script question

Unix script question

Post by qwert » Thu, 24 Oct 2002 00:21:31



How would you handle the following :-

# cat > file1
DIR=/home/test&prog=qwerty&var=123,345,678
^d

layout would always be the same, but variable fields / values.
How could I just display the /home/test element from a one liner text file
given that it would always be preeced by DIR= and always be the first
element,
this is all I want to know, in the form of a shell script.
the DIR is not to specify the script, just the working directory.

Tried grep but that only returns the complete line, how do I do this in a
script please ??

Thanks

Rev

 
 
 

Unix script question

Post by Stephane Chazela » Thu, 24 Oct 2002 00:27:59



> How would you handle the following :-

> # cat > file1
> DIR=/home/test&prog=qwerty&var=123,345,678
> ^d

[...] -> /home/test

sed -ne 's/^DIR=\([^&]*\).*/\1/p;q' file1
# (not tested)

But you may have to do further processing (decoding) for cases where
some of the characters in DIR are URL encoded.

--
Stphane

 
 
 

Unix script question

Post by qwert » Thu, 24 Oct 2002 01:07:35


Stephanie, many thanks - it works, your brilliant !!
Any good links for me to read up on this stuff ?

Thanks

Rev




> > How would you handle the following :-

> > # cat > file1
> > DIR=/home/test&prog=qwerty&var=123,345,678
> > ^d
> [...] -> /home/test

> sed -ne 's/^DIR=\([^&]*\).*/\1/p;q' file1
> # (not tested)

> But you may have to do further processing (decoding) for cases where
> some of the characters in DIR are URL encoded.

> --
> Stphane

 
 
 

Unix script question

Post by Stephane Chazela » Thu, 24 Oct 2002 01:21:19



> Any good links for me to read up on this stuff ?

RFC 1738: http://www.rfc-editor.org/rfc/rfc1738.txt
man sed
sed FAQ: http://www.faqs.org/faqs/editor-faq/sed/

--
Stphane (without "i")

 
 
 

Unix script question

Post by qwert » Thu, 24 Oct 2002 02:13:05


Stphane , sincere appologies, I was so pleased to get a simple answer to my
question, that my fingers ran away with themselves !

Many thanks for your help, much appreciated, and once again appologies for
the typo.

Rgds

Rev.