PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Removing of Double Quotes from command output
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Removing of Double Quotes from command output

Réponse
 
LinkBack Outils de la discussion
Vieux 03/12/2006, 07h59   #1
Polani
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Removing of Double Quotes from command output

Guys!!

I need some in removing double quotes from a command output.
Actually , as a result of command , i am getting a device name
surrounded by double quotes.

Output something like that "

parent = "ide0"

but this device name varies in length so i wish to find any way to
remove these double quotes and give me only ide0 or pci4 etc... that
is no more double quotes...

How can i so that ... please me

Thanks and best regards

Polani

  Réponse avec citation
Vieux 03/12/2006, 08h12   #2
RolandRB
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing of Double Quotes from command output


Polani wrote:
> Guys!!
>
> I need some in removing double quotes from a command output.
> Actually , as a result of command , i am getting a device name
> surrounded by double quotes.
>
> Output something like that "
>
> parent = "ide0"
>
> but this device name varies in length so i wish to find any way to
> remove these double quotes and give me only ide0 or pci4 etc... that
> is no more double quotes...
>
> How can i so that ... please me
>
> Thanks and best regards
>
> Polani


I am suprised it is giving you a problem. You can always assign it to
itself as an extra step so long as there will be no spaces in the name.

parent=$parent

  Réponse avec citation
Vieux 03/12/2006, 10h21   #3
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing of Double Quotes from command output

2006-12-2, 23:59(-08), Polani:
> Guys!!
>
> I need some in removing double quotes from a command output.
> Actually , as a result of command , i am getting a device name
> surrounded by double quotes.
>
> Output something like that "
>
> parent = "ide0"
>
> but this device name varies in length so i wish to find any way to
> remove these double quotes and give me only ide0 or pci4 etc... that
> is no more double quotes...

[...]

echo 'parent = "ide0"' | tr -d '"'

--
Stéphane
  Réponse avec citation
Vieux 03/12/2006, 13h04   #4
Radoulov, Dimitre
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing of Double Quotes from command output


"Polani" <kshiraz12@hotmail.com> wrote in message
news:1165132778.849241.47970@j72g2000cwa.googlegro ups.com...
> Guys!!
>
> I need some in removing double quotes from a command output.
> Actually , as a result of command , i am getting a device name
> surrounded by double quotes.
>
> Output something like that "
>
> parent = "ide0"
>
> but this device name varies in length so i wish to find any way to
> remove these double quotes and give me only ide0 or pci4 etc... that
> is no more double quotes...

[...]


$ eval echo 'parent = "ide0"'
parent = ide0


Regards
Dimitre



  Réponse avec citation
Vieux 03/12/2006, 17h26   #5
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing of Double Quotes from command output

On 2006-12-03, Polani wrote:
> Guys!!
>
> I need some in removing double quotes from a command output.
> Actually , as a result of command , i am getting a device name
> surrounded by double quotes.
>
> Output something like that "
>
> parent = "ide0"
>
> but this device name varies in length so i wish to find any way to
> remove these double quotes and give me only ide0 or pci4 etc... that
> is no more double quotes...


You could use cut with the -f and -d options:

cut -d \" -f2


Or awk:

awk -F\" '{ print $2 }'


Or sed:

sed 's/.*\"\([^\"]*\)\".*/\1/'


Or, if you have it in a variable, use the shell field separator:

dev='parent = "ide0"'
set -f
IFS=\"
set -- $dev
dev=$2


Or parameter expansion:

dev='parent = "ide0"'
dev=${dev#*\"}
dev=${dev%\"*}


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 03/12/2006, 18h36   #6
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing of Double Quotes from command output

2006-12-3, 12:26(-05), Chris F.A. Johnson:
[...]
> Or parameter expansion:
>
> dev='parent = "ide0"'
> dev=${dev#*\"}
> dev=${dev%\"*}

[...]

Or simply expr:

dev=$(
expr "$dev" : 'parent = "\(.*\)"'
)

zsh specific:

dev=${dev/(#b)parent = \"(*)\"/$match[1]}

Or:

if [[ $dev = 'parent = "'(*)'"' ]]; then
dev=$match[1]
fi

--
Stéphane
  Réponse avec citation
Vieux 03/12/2006, 18h47   #7
Janis Papanagnou
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing of Double Quotes from command output

Stephane CHAZELAS wrote:
> 2006-12-3, 12:26(-05), Chris F.A. Johnson:
> [...]
>
>> Or parameter expansion:
>>
>>dev='parent = "ide0"'
>>dev=${dev#*\"}
>>dev=${dev%\"*}

>
> [...]
>
> Or simply expr:
>
> dev=$(
> expr "$dev" : 'parent = "\(.*\)"'
> )


Is there any shell where 'expr' is builtin?
To avoid the averhead of the two processes.

Janis

>
> zsh specific:
>
> dev=${dev/(#b)parent = \"(*)\"/$match[1]}
>
> Or:
>
> if [[ $dev = 'parent = "'(*)'"' ]]; then
> dev=$match[1]
> fi
>

  Réponse avec citation
Vieux 03/12/2006, 20h00   #8
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing of Double Quotes from command output

On 2006-12-03, Stephane CHAZELAS wrote:
> 2006-12-3, 12:26(-05), Chris F.A. Johnson:
> [...]
>> Or parameter expansion:
>>
>> dev='parent = "ide0"'
>> dev=${dev#*\"}
>> dev=${dev%\"*}

> [...]
>
> Or simply expr:


s/simply/slowly/

> dev=$(
> expr "$dev" : 'parent = "\(.*\)"'
> )
>
> zsh specific:
>
> dev=${dev/(#b)parent = \"(*)\"/$match[1]}
>
> Or:
>
> if [[ $dev = 'parent = "'(*)'"' ]]; then
> dev=$match[1]
> fi
>



--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 04/12/2006, 21h02   #9
Sven Mascheck
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing of Double Quotes from command output

Janis Papanagnou wrote:

> Is there any shell where 'expr' is builtin?


Possibly none, if you want an almost identical implementation.
See also <slrndc7a9q.6ch.stephane.chazelas@spam.is.invalid> .
--
  Réponse avec citation
Vieux 04/12/2006, 21h18   #10
William Park
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing of Double Quotes from command output

Polani <kshiraz12@hotmail.com> wrote:
> Guys!!
>
> I need some in removing double quotes from a command output.
> Actually , as a result of command , i am getting a device name
> surrounded by double quotes.
>
> Output something like that "
>
> parent = "ide0"
>
> but this device name varies in length so i wish to find any way to
> remove these double quotes and give me only ide0 or pci4 etc... that
> is no more double quotes...
>
> How can i so that ... please me
>
> Thanks and best regards
>
> Polani


sed 's,",,'

--
William Park <opengeometry@yahoo.ca>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
http://freshmeat.net/projects/bashdiff/
  Réponse avec citation
Vieux 04/12/2006, 23h45   #11
Janis Papanagnou
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing of Double Quotes from command output

Sven Mascheck wrote:
> Janis Papanagnou wrote:
>
>>Is there any shell where 'expr' is builtin?

>
> Possibly none, if you want an almost identical implementation.


No; it was a rhetorical question because calling expr in a subshell
(as suggested) is slow; it requires two unnecessary processes.

Janis
  Réponse avec citation
Vieux 05/12/2006, 01h27   #12
bsh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing of Double Quotes from command output


Polani wrote:
> parent = "ide0" => parent = ide0


Tr? Sed!? Awk!!? Perl!!!? *Sheesh!*

Columbus tried to find a passage to the West Indies by
going the wrong way around the world too....

I suggest:

set -- $the_string
echo $3

=Brian

  Réponse avec citation
Vieux 05/12/2006, 02h42   #13
Janis Papanagnou
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing of Double Quotes from command output

bsh wrote:
> Polani wrote:
>
>>parent = "ide0" => parent = ide0

>
>
> Tr? Sed!? Awk!!? Perl!!!? *Sheesh!*
>
> Columbus tried to find a passage to the West Indies by
> going the wrong way around the world too....
>
> I suggest:
>
> set -- $the_string
> echo $3
>
> =Brian
>


$ the_string='parent = "ide0"'
$ set -- $the_string
$ echo $3
"ide0"

But the OP wanted to remove of double quotes from command output.

Janis
  Réponse avec citation
Vieux 05/12/2006, 08h35   #14
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing of Double Quotes from command output

2006-12-05, 00:45(+01), Janis Papanagnou:
> Sven Mascheck wrote:
>> Janis Papanagnou wrote:
>>
>>>Is there any shell where 'expr' is builtin?

>>
>> Possibly none, if you want an almost identical implementation.

>
> No; it was a rhetorical question because calling expr in a subshell
> (as suggested) is slow; it requires two unnecessary processes.

[...]

AFAICS, only bash forks twice there. Most other shells (at least
ash, zsh, AT&T ksh and pdksh) fork only once.

But remember a shell is a tool to execute commands. It can't be
definitely wrong to call the expr command. If you've got more
that one substitution to do, you can use sed or awk instead.

--
Stéphane
  Réponse avec citation
Vieux 05/12/2006, 16h36   #15
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing of Double Quotes from command output

On 2006-12-05, Stephane CHAZELAS wrote:
>
> But remember a shell is a tool to execute commands.


And it is much more than that. A POSIX shell is a complete
programming language, needing external command much less than the
Bourne shell.

> It can't be definitely wrong to call the expr command.


It's not wrong, but it is very inefficient.

> If you've got more that one substitution to do, you can use sed or
> awk instead.


If you know there are only a few, using a shell loop will still be
faster than an external command.

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 05/12/2006, 16h39   #16
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing of Double Quotes from command output

On 2006-12-05, Janis Papanagnou wrote:
> bsh wrote:
>> Polani wrote:
>>
>>>parent = "ide0" => parent = ide0

>>
>>
>> Tr? Sed!? Awk!!? Perl!!!? *Sheesh!*
>>
>> Columbus tried to find a passage to the West Indies by
>> going the wrong way around the world too....
>>
>> I suggest:
>>
>> set -- $the_string
>> echo $3
>>
>> =Brian
>>

>
> $ the_string='parent = "ide0"'
> $ set -- $the_string
> $ echo $3
> "ide0"
>
> But the OP wanted to remove of double quotes from command output.


eval "echo $3"

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 05/12/2006, 22h53   #17
bsh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Removing of Double Quotes from command output


Chris F.A. Johnson wrote:
> Janis Papanagnou wrote:
> > bsh wrote:
> > > Polani wrote:

> > ...

> eval "echo $3"


Darn it! Yes, I meant to add the "eval". Thank you
for the correction, Chris.

=Brian

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 14h20.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,21250 seconds with 25 queries