简体   繁体   中英

awk timestamp set in begin block

I'm setting a timestamp in a begin block:

BEGIN  { 
  timestamp = strftime("%Y%m%d%H%M%S");
}

I don't update timestamp again in the rest of the script. I expect that timestamp won't change but it does.

Later in the script, I print $0 to a file:

FNR>1{
  #do some stuff
  print $0 > "/mnt/data/logs/TEST_"timestamp".csv"
  ...

timestamp changes and it keeps printing to a new file. . . TEST_1.csv, TEST_2.csv . . .

It works as expected on a small file but when I use a full data file it prints multiple files

OK guys, I figured out the issue. I am calling an auxiliary awk script that I didn't think was relevant. Sorry for not including that originally. So when I call a logger function on that script it updates the timestamp variable. I fixed the issue by simply changing timestamp to timestamp1 on my script.

Thanks to all that responded and put up with my awk inexperience!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM