I am trying get printf
to output multiple variables on a single line.
Having difficultly with argument handling and formats for printf
and receiving unexpected results.
Code snippet
printf '%s %s %s' $infile $insize $indate 2>&1 | tee -a $logfile
find $infile -printf ' %p %s %CY-%Cm-%Cd %CH:%CM:%.2TS \n' 2>&1 | tee -a $logfile
Unexpected result
* first file size not showing, date and time not correct (printf)
* second file size correct, date and time not correct (find -printf)
ftp://ftp.ncbi.nlm.nih.gov/pub/README.ftp 2019-08-25 00:00:00 ./README.ftp 2037 2019-08-25 14:22:26
Expected result
ftp://ftp.ncbi.nlm.nih.gov/pub/README.ftp 2037 2015-08-12 15:47:26 ./README.ftp 2037 2019-08-24 20:32:53
Remote file
Last-Modified: Wed, 12 Aug 2015 15:47:26 GMT
Content-Length: 2037
Local file
2037 Aug 13 2015 README.ftp
Thanks in advance.
Solution
printf '%s %d %s' "$infile" "$insize" "$indate" 2>&1 | tee -a "$logfile"
find "$infile" -printf ' %p %s %CY-%Cm-%Cd %CH:%CM:%.2TS \n' 2>&1 | tee -a "$logfile"
Result
ftp://ftp.ncbi.nlm.nih.gov/pub/README.ftp 2037 2015-08-12 15:47:26 ./README.ftp 2037 2019-08-24 20:32:53
man 1 printf
clear and simple explanation of argument handing.
GNU Manual Table of Output Conversions for format summary
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.