vskubriev
vskubriev

Reputation: 858

Replace a unix timestamp in csv file. Newline issue

I have a command that outputs to stdout lines like:

1508425884.382198,30
1508425885.383406,30

I want to replace a unixtimestamp 1508485425.712408 with another date format in place.

I tried following cases:

awk -F ',' -v OFS=',' '$1 { system( "date -d @" $1 ); print $2}'
awk -F ',' -v OFS=',' '$1 { print strftime("%F %H:%M", $1); print $2}'
awk -F ',' -v OFS=',' '$1 { print strftime("%c", $1); print $2}'

But unfortunately everyone outputs after the date the character of the end of the line. With first case I also tried to add tr -d '\n' with pipe like following:

awk -F ',' -v OFS=',' '$1 { system( "date -d @" $1 "| tr -d '\n'" $1 ); print $2}'

But it seems non-working solution.

That's was I getting:

Thu Oct 19 18:11:24 +03 2017
30
Thu Oct 19 18:11:25 +03 2017
30

That's what I'am looking for:

Thu Oct 19 18:11:24 +03 2017, 30
Thu Oct 19 18:11:25 +03 2017, 30

Upvotes: 2

Views: 63

Answers (1)

RomanPerekhrest
RomanPerekhrest

Reputation: 92854

print statement outputs all its arguments on a separate line.
Just use a singe print statement:

awk -F',' '{ print strftime("%c", $1),$2 }' OFS=','

Upvotes: 4

Related Questions