LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Remove double quotes bash (https://www.linuxquestions.org/questions/programming-9/remove-double-quotes-bash-892703/)

alancampbell6 07-20-2011 06:17 AM

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

colucix 07-20-2011 06:27 AM

No need for grep if using awk:
Code:

awk '/XkbLayout/ && !/^#/ {gsub(/"/,"",$3); print $3}' /etc/X11/xorg.conf

alancampbell6 07-20-2011 06:30 AM

Thank you very helpful

gnashley 07-20-2011 02:36 PM

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


bigearsbilly 07-20-2011 03:05 PM

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



All times are GMT -5. The time now is 09:36 AM.