|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
"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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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 > |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
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> . -- |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
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/ |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#13 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#14 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#15 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#16 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#17 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|