process substitution with awk, output splitting incorrectly
I have the following code to extract two dates using awk, which are then read into two awk variables new and old respectively.
Each dates on the html file pulled with curl request is in this format: 2015-04-06 09:40:37 And two are being extracted However the strings are being split on white space within the date strings. I tried changing OFS to ',', but it was still splitting incorrectly. Code:
read dateStrNew dateStrOld < <(curl -k -q "$curl_call" | html2text | gawk '/Newest Sequence/ { new=$3" "$4 }/Oldest Sequence/ \ I just can't work out what is wrong, any help would be very much appreciated! Thanks! |
Hi,
the culprit here is the shell (bash?), rather than awk. awk outputs a line that contains spaces and read splits it. If you want to prevent that, you need to change the IFS variable in the shell: Code:
IFS=, read dateStrNew dateStrOld < <(curl -k -q "$curl_call" | html2text | gawk '/Newest Sequence/ { new=$3" "$4 }/Oldest Sequence/ \ |
Quote:
|
Quote:
Code:
IFS="," Code:
curl -k -q "$curl_call" | html2text |
Ah, well it's good to know that is a way of temporarily setting the IFS.
Yes I did. Sample output: newest , oldest newest 2015-04-07 06 oldest 29:29,2015-04-06 09:40:37 newest , oldest newest 2015-04-07 06 oldest 29:29,2015-04-06 09:40:37 So you can see that the comma is being read in the first variable, followed by whitespace/nothing. Then the first part of the first date string Then the second part of the first date string plus all of the second date string then a comma etc |
All times are GMT -5. The time now is 04:42 AM. |