Hello,
i was just wondering how can i use shell command in awk script file? say suppose i want to print the date at the top of the report i generate using awk how can i do that? Thanks in advance!
Possibilities:
awk 'BEGIN{"date" | getline d; print d; close("date")}
{# Other commands....}
' file
Or:
awk -v d="$(date)" 'BEGIN{print d}
{# Other commands....}
' file
Or:
awk 'BEGIN{system("date")}
{# Other commands....}
' file
Regards
thanks Franklin52,
the last one is the easiest for me haha! and can you please tell me how can i do the following in awk script file?
for i in `ls`
do
echo $i
done
also why is this not working?
BEGIN{
system("date \"+%H-%M\"")|getline d
}
{
}
Do you mean something like this?
awk 'BEGIN{
while ("ls" | getline var){
#Do something with var...}
}
{...}'
The system command returns the exit status of the command that was executed not the output of the command.
Regards
Thanks again Franklin52
now things getting into my mind.