Re: Extract substring from cat

2015-10-18 Thread tomas
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Sun, Oct 18, 2015 at 09:58:01PM +0200, Kurt Flex wrote:
> On Fri, Oct 16, 2015 at 03:14:31PM +0200, to...@tuxteam.de wrote:
> > On Fri, Oct 16, 2015 at 02:54:25PM +0200, Nemeth Gyorgy wrote:
> > > 2015-10-16 14:15 keltezéssel, Alfred Charles Stockton írta:
> > > cat /etc/*-release | grep ^PRETTY_NAME | sed 's/^.*=//'
> > 
> > Many insightful answers have been given. Yours is an example of "useless
> > use of cat" [1], better spelt as
> >
> >   grep ^PRETTY_NAME /etc/*-release | sed 's/^.*=//'
> > 
> > Even better, since sed can do grep:
> > 
> >   sed -ne '/^PRETTY_NAME=/ s/^.*=// p' < /etc/*-release
> 
> Not if there may be more than one file matching the pattern. In that
> case at least your "better" example breaks. It can be fixed by
> omitting "<".

You are right, of course. Thanks :-)
- -- tomás
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.12 (GNU/Linux)

iEUEARECAAYFAlYj8pwACgkQBcgs9XrR2kanlQCYsVXb2pIomOKeQaqCNTbEKrqZ
dQCfSIKTynqVZCWbxKlfc6NL/AVBNvI=
=I46h
-END PGP SIGNATURE-



Re: Extract substring from cat

2015-10-18 Thread Kurt Flex
On Fri, Oct 16, 2015 at 03:14:31PM +0200, to...@tuxteam.de wrote:
> On Fri, Oct 16, 2015 at 02:54:25PM +0200, Nemeth Gyorgy wrote:
> > 2015-10-16 14:15 keltezéssel, Alfred Charles Stockton írta:
> > cat /etc/*-release | grep ^PRETTY_NAME | sed 's/^.*=//'
> 
> Many insightful answers have been given. Yours is an example of "useless
> use of cat" [1], better spelt as
>
>   grep ^PRETTY_NAME /etc/*-release | sed 's/^.*=//'
> 
> Even better, since sed can do grep:
> 
>   sed -ne '/^PRETTY_NAME=/ s/^.*=// p' < /etc/*-release

Not if there may be more than one file matching the pattern. In that
case at least your "better" example breaks. It can be fixed by
omitting "<".


Kurt



Extract substring from cat

2015-10-16 Thread Alfred Charles Stockton

If I issue the command cat /etc/*-release on my Debian system I get:-

PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
NAME="Debian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=debian
HOME_URL="http://www.debian.org/;
SUPPORT_URL="http://www.debian.org/support/;
BUG_REPORT_URL="https://bugs.debian.org/;

Now what I would like to do is to only print the substring "Debian
GNU/Linux 8 (jessie)" from the 1st line, preferably in bash.

Please tell me how I should go about this?

--
Regards,
Alf Stockton




Re: Extract substring from cat

2015-10-16 Thread tomas
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Fri, Oct 16, 2015 at 02:54:25PM +0200, Nemeth Gyorgy wrote:
> 2015-10-16 14:15 keltezéssel, Alfred Charles Stockton írta:
> > 
> > If I issue the command cat /etc/*-release on my Debian system I get:-
> > 
> > PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
> > NAME="Debian GNU/Linux"
> > VERSION_ID="8"
> > VERSION="8 (jessie)"
> > ID=debian
> > HOME_URL="http://www.debian.org/;
> > SUPPORT_URL="http://www.debian.org/support/;
> > BUG_REPORT_URL="https://bugs.debian.org/;
> > 
> > Now what I would like to do is to only print the substring "Debian
> > GNU/Linux 8 (jessie)" from the 1st line, preferably in bash.
> > 
> > Please tell me how I should go about this?
> > 
> > --
> > Regards,
> > Alf Stockton
> > 
> > 
> > 
> cat /etc/*-release | grep ^PRETTY_NAME | sed 's/^.*=//'

Many insightful answers have been given. Yours is an example of "useless
use of cat" [1], better spelt as

  grep ^PRETTY_NAME /etc/*-release | sed 's/^.*=//'

Even better, since sed can do grep:

  sed -ne '/^PRETTY_NAME=/ s/^.*=// p' < /etc/*-release

[1] 

regards
- -- t
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlYg+DYACgkQBcgs9XrR2kYxKACdHFb8xn/cjQU5of0vsRmxnUXZ
INAAnA3MxfnslHQPQ0Cw9TIOwWxcpI7F
=xsvX
-END PGP SIGNATURE-



Re: Extract substring from cat

2015-10-16 Thread Nemeth Gyorgy
2015-10-16 14:15 keltezéssel, Alfred Charles Stockton írta:
> 
> If I issue the command cat /etc/*-release on my Debian system I get:-
> 
> PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
> NAME="Debian GNU/Linux"
> VERSION_ID="8"
> VERSION="8 (jessie)"
> ID=debian
> HOME_URL="http://www.debian.org/;
> SUPPORT_URL="http://www.debian.org/support/;
> BUG_REPORT_URL="https://bugs.debian.org/;
> 
> Now what I would like to do is to only print the substring "Debian
> GNU/Linux 8 (jessie)" from the 1st line, preferably in bash.
> 
> Please tell me how I should go about this?
> 
> --
> Regards,
> Alf Stockton
> 
> 
> 
cat /etc/*-release | grep ^PRETTY_NAME | sed 's/^.*=//'

-- 
--- Friczy ---
'Death is not a bug, it's a feature'



Re: Extract substring from cat

2015-10-16 Thread Santiago Vila
On Fri, Oct 16, 2015 at 02:15:46PM +0200, Alfred Charles Stockton wrote:
> Now what I would like to do is to only print the substring "Debian
> GNU/Linux 8 (jessie)" from the 1st line, preferably in bash.

The standard says /etc/os-release is shell-compatible, so I would do this:

. /etc/os-release
echo ${PRETTY_NAME}



Re: Extract substring from cat

2015-10-16 Thread Darac Marjal
On Fri, Oct 16, 2015 at 02:15:46PM +0200, Alfred Charles Stockton wrote:
> 
> If I issue the command cat /etc/*-release on my Debian system I get:-
> 
> PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
> NAME="Debian GNU/Linux"
> VERSION_ID="8"
> VERSION="8 (jessie)"
> ID=debian
> HOME_URL="http://www.debian.org/;
> SUPPORT_URL="http://www.debian.org/support/;
> BUG_REPORT_URL="https://bugs.debian.org/;
> 
> Now what I would like to do is to only print the substring "Debian
> GNU/Linux 8 (jessie)" from the 1st line, preferably in bash.
> 
> Please tell me how I should go about this?

The EASY way? "( source /etc/*-release; echo $PRETTY_NAME )".

'source' executes the commands in the file(s) which, in this case, are 
simple variable assignments. 'echo' prints the contents of one of those 
variables. Finally "( ... ; ... )" executes the two commands one after 
the other in a subshell. When the subshell exits (after the echo 
command), the variables will be forgotten.

> 
> --
> Regards,
> Alf Stockton
> 
> 

-- 
For more information, please reread.


signature.asc
Description: PGP signature


Re: Extract substring from cat

2015-10-16 Thread John L. Cunningham
On Fri, Oct 16, 2015 at 02:15:46PM +0200, Alfred Charles Stockton wrote:
> 
> If I issue the command cat /etc/*-release on my Debian system I get:-
> 
> PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
> NAME="Debian GNU/Linux"
> VERSION_ID="8"
> VERSION="8 (jessie)"
> ID=debian
> HOME_URL="http://www.debian.org/;
> SUPPORT_URL="http://www.debian.org/support/;
> BUG_REPORT_URL="https://bugs.debian.org/;
> 
> Now what I would like to do is to only print the substring "Debian
> GNU/Linux 8 (jessie)" from the 1st line, preferably in bash.
> 
> Please tell me how I should go about this?

$ gawk -F= '/^PRETTY/{ print $2 }' /etc/*-release



Re: Extract substring from cat

2015-10-16 Thread Jonathan
On Fri, 16 Oct 2015 14:15:46 +0200
"Alfred Charles Stockton"  wrote:

> Now what I would like to do is to only print the substring "Debian
> GNU/Linux 8 (jessie)" from the 1st line, preferably in bash.
> 
> Please tell me how I should go about this?

lsb_release -ds
from lsb-release package.



Re: Extract substring from cat

2015-10-16 Thread Cindy-Sue Causey
On 10/16/15, Jonathan  wrote:
> On Fri, 16 Oct 2015 14:15:46 +0200
> "Alfred Charles Stockton"  wrote:
>
>> Now what I would like to do is to only print the substring "Debian
>> GNU/Linux 8 (jessie)" from the 1st line, preferably in bash.
>>
>> Please tell me how I should go about this?
>
> lsb_release -ds
> from lsb-release package.


I've been partially playing along with this thread as it has evolved.
I received 2 slightly different outputs regarding this latest..

$ lsb_release -ds
$ Debian GNU/Linux unstable (sid)

and...

$ cat /etc/*-release
$ PRETTY_NAME="Debian GNU/Linux stretch/sid"

Unstable is certainly Sid's first, middle, and last name, grin.
Stretch nicely defines where Sid is in a release cycle of the
moment. a nice little time stamp of sorts ish. :)

Cindy :)

-- 
Cindy-Sue Causey
Talking Rock, Pickens County, Georgia, USA

* runs with duct tape *