Reputation: 365
I want to transfer first field of a csv file, but with a certain delay e.g. 1 second after every element. I am using awk to pull the first field and then send it using netcat. I am using the following command but it has no delay.
awk -F, '{print $1}' sample.csv | netcat -lk 9999
Any hints would be much appreciated.
Upvotes: 0
Views: 650
Reputation: 3838
You could use bash
instead of awk
in this case :
while IFS="," read -ra array; do echo "${array[0]}"; sleep 1; done < sample.csv|netcat -lk 9999
Upvotes: 1
Reputation:
You can use system within awk to execute shell commands such as sleep.
awk -F, '{system("sleep 1");print $1}' sample.csv | netcat -lk 9999
A word of warning though, using system can sometimes make it difficult to cancel a command half way through with ^C
as it cancels the system call but not awk.
Upvotes: 4