shell how to write a file as the file name in the first column

1. Create a temporary file TMPFILE (I assume that the file named aaa_td)

file=aaa_td

TMPFILE=$(mktemp ${file%_*}.XXXXXX) || exit 1

Note: {file% _ *} represents the file name "_" section before

2. aaa_td write temporary files (each row of spaces with \ t Replace)

cat $ file | tr "" "\ t"> $ TMPFILE # data is written to a temporary file

3. Get "_" before the file name

name=${file%_*}

4. The file name as the first row, separated by Tab, writing the new file

awk '{print $0"\t'$name'"}' $TMPFILE >${file%_*}.txt

 

Guess you like

Origin www.cnblogs.com/xuebf/p/11778130.html