LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-20-2011, 06:17 AM   #1
alancampbell6
LQ Newbie
 
Registered: Jul 2011
Posts: 16

Rep: Reputation: Disabled
Remove double quotes bash


grep -e XkbLayout /etc/X11/xorg.conf | grep -v "^#" | awk '{print $3}'

output = "gb"
sometimes= "us"

anyone know how to make the ouputs
gb
us
 
Old 07-20-2011, 06:27 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982
No need for grep if using awk:
Code:
awk '/XkbLayout/ && !/^#/ {gsub(/"/,"",$3); print $3}' /etc/X11/xorg.conf
 
1 members found this post helpful.
Old 07-20-2011, 06:30 AM   #3
alancampbell6
LQ Newbie
 
Registered: Jul 2011
Posts: 16

Original Poster
Rep: Reputation: Disabled
Thank you very helpful
 
Old 07-20-2011, 02:36 PM   #4
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,902

Rep: Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590
How about a little less awk? set makes a handy substitue for awk when simply printing out a certain field:
Code:
set $(grep -e XkbLayout /etc/X11/xorg.conf | grep -v "^#")
echo $3
Too bad about the two calls to grep, but case makes a handy substitute for simple pattern-matching. To keep it all in bash:
Code:
while read LINE ; do
    case "$LINE" in
	\#*) : ;;
	*XkbLayout*) set $LINE ; echo ${3//\"/} ;;
    esac
done < /etc/X11/xorg.conf

Last edited by gnashley; 07-20-2011 at 02:44 PM.
 
Old 07-20-2011, 03:05 PM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: NetBSD, Void, Debian, Mint, Ubuntu, Puppy, Raspbian
Posts: 3,487

Rep: Reputation: 233Reputation: 233Reputation: 233
a few methods!

Code:
grep -e XkbLayout /etc/X11/xorg.conf | grep -v "^#" | tr -d \"

Code:
$ x='"fish"' 
       
$ echo $x   
"fish"

$ echo $x | tr -d \"
fish

$ eval echo $x      
fish

$ echo ${x//\"/}
fish

Last edited by bigearsbilly; 07-20-2011 at 03:07 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] double-quotes do not escape properly (bash=python) fabienhenon Programming 3 05-03-2010 03:23 PM
Bash - double quotes don't protect Exclamation marks geoff_f Programming 15 04-15-2007 09:10 PM
Using single quotes vs double quotes in PHP strings vharishankar Programming 6 07-11-2005 11:41 AM
In BASH shell, what is the difference in usage between single and double quotes? davidas Linux - Newbie 2 04-05-2004 03:00 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration