S
S
srgsrg19012021-06-10 10:56:06
linux
srgsrg1901, 2021-06-10 10:56:06

Awk how to concatenate columns when passed to shell?

Good afternoon
4th field 15-Aug-2019
5th field 00:24:38 the
expression works
awk '{z=system("date --date="$4" +%s")} {printz}'
this is no longer

awk '{z=system("date --date="$4" "$5" +%s")} {printz}'

Try 'date --help' for more information.
date: extra operand '+%s'

the second field is perceived as an argument
How to escape correctly?
I went through all combinations of brackets and quotes

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xotkot, 2021-06-10
@srgsrg1901

$ echo "a1 a2 a3 15-Aug-2019 00:24:38 a6 ..." | awk '{z="date -d \""$4" "$5"\" \"+%s\""; z | getline z; print z}'
1565817878

well, or output in the line itself
$ echo "a1 a2 a3 15-Aug-2019 00:24:38 a6 ..." | awk '{z="date -d \""$4" "$5"\" \"+%s\""; z | getline z; $4=z;$5="";print}'
a1 a2 a3 1565817878  a6 ...

a little shorter
$ echo "a1 a2 a3 15-Aug-2019 00:24:38 a6 ..." | awk '{"date -d \""$4" "$5"\" \"+%s\""|getline $4;$5="";print}'
a1 a2 a3 1565817878  a6 ...

upd . (correction)
$ echo "a1 a2 a3 15-Aug-2019 00:24:38 a6 ..." | awk '{"date -d \""$4" "$5"\" \"+%s\"" | getline z; $4=z;$5="";print}'
a1 a2 a3 1565817878  a6 ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question