Hi
I am trying to do
awk -F: '{print $3}' a:b:c
to get c.
awk however expects a file:
awk: can't open a:b:c
any idea?
Hi
I am trying to do
awk -F: '{print $3}' a:b:c
to get c.
awk however expects a file:
awk: can't open a:b:c
any idea?
Please place your code between code tags.
You can select your code and click on the # symbol above the edit window or place your code between code brackets as follow:
awk -F: '{print $3}' file
It's the expected behavior. If you really need to do something like this with AWK, you should write something like this:
awk 'BEGIN {
split(ARGV[1], t, ":")
print t[3]
}' a:b:c
For a string try this:
assuming: var="a:b:c"
echo "$var" | awk -F: '{print $3}'
More possibilities:
echo 'a:b:c' | sed 's/.*://'
Or:
echo 'a:b:c' | awk -F: '$0=$3'
Actually,
it could be easily done in shell without any external command
(unless, as already stated, there is another reason to use AWK in this particular case):
% s=a:b:c
% (IFS=:;set -- $s;printf "$3\n")
c
With Z-Shell:
zsh-4.3.4% print ${${(s.:.)s}[3]}
c