You are not logged in.
Why doesn't `bash -c "echo 1 2 3 | awk '{print $1}'"' print `1' instead of `1 2 3'? It seems to be a bug in `awk', because running `bash -c "echo 1 2 3 | sed -e 's|1|5|'"' prints `5 2 3'.
Last edited by deltaecho (2009-03-10 20:20:01)
Dylon
Offline
I'm not sure if it's a awk bug:
echo 1 2 3 | awk '{print $1}'
1
zsh -c "echo 1 2 3 | awk '{print $1}'"
1 2 3
(lambda ())
Offline
umm...
abesto ~ $ echo 1 2 3 | awk '{print $1}'
1
It's fine here. I don't think the problem is with awk.
Last edited by abesto (2009-03-10 19:56:25)
Linux user #476135 || Dotfiles hosted by GitHub
Offline
Running
$ echo 1 2 3 | awk '{print $1}'
does work, but running
$ bash -c "echo 1 2 3 | awk '{print $1}'"
does not.
Dylon
Offline
The $1 is interpreted as an empty string, even though it is in single quotes, so you are running echo 1 2 3 | awk '{print }'
Instead try this:
$ bash -c "echo 1 2 3 | awk '{print \$1}'"
1
Also see bash -x -c
--> bash -x -c "echo 1 2 3 | awk '{print $1}'"
+ echo 1 2 3
+ awk '{print }'
1 2 3
--> bash -x -c 'echo 1 2 3 | awk "{print $1}"'
+ echo 1 2 3
+ awk '{print }'
1 2 3
--> bash -x -c "echo 1 2 3 | awk '{print \$1}'"
+ awk '{print $1}'
+ echo 1 2 3
1
Offline
The $1 is interpreted as an empty string, even though it is in single quotes, so you are running echo 1 2 3 | awk '{print }'
Instead try this:
$ bash -c "echo 1 2 3 | awk '{print \$1}'"
1Also see bash -x -c
--> bash -x -c "echo 1 2 3 | awk '{print $1}'" + echo 1 2 3 + awk '{print }' 1 2 3 --> bash -x -c 'echo 1 2 3 | awk "{print $1}"' + echo 1 2 3 + awk '{print }' 1 2 3 --> bash -x -c "echo 1 2 3 | awk '{print \$1}'" + awk '{print $1}' + echo 1 2 3 1
That works! Thanks @Procyon!
Dylon
Offline