简体   繁体   中英

How append the username into the file name

I have this script,

find -iname \*.${EXT} -print0 | xargs -0 ls -l --time-style="+%b %Y" | awk '{print $NF,$3,$5,$6,$7}' OFS="\t" > ${EXT}.txt
awk -vextension="${EXT}" -vfiletype="${TYPE}" -vcompress="${COMP}" -vOFS="\t" '{print $0, ext, filetype, compress}' < ${EXT}.txt >> all.txt

I would like alter the script to automatically append the username of user that ran this script into the file eg “Jason_all.txt” as final output.

Simple :

find -iname \*.${EXT} -print0 | xargs -0 ls -l --time-style="+%b %Y" | awk '{print $NF,$3,$5,$6,$7}' OFS="\t" > ${EXT}.txt
awk -vextension="${EXT}" -vfiletype="${TYPE}" -vcompress="${COMP}" -vOFS="\t" '{print $0, ext, filetype, compress}' < ${EXT}.txt >> "${USER}_all.txt"

Better edit this snippet to not parsing ls output

Check man find | less +/'printf format' man find | less +/'printf format' instead

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