Using below function to filter out text file and organize to new format.
Using unix redirection >
command to create new files.
How can I get rid of creating all new files
(e.g. ${file}_final_1.txt,${file}only${pattern}.txt)
without deleting it afterword using rm
command ?
filter(){
cat ${file}_1.txt | grep -v ${pattern} > ${file}_final_1.txt
cat ${file}_1.txt | grep ${pattern} > ${file}_only_${pattern}.txt
cat ${file}_only_${pattern}.txt | nawk -F '|' '{ print $NF}' > ${pattern}_TS.txt
paste ${pattern}_TS.txt ${file}_only_${pattern}.txt > ${pattern}_TS_file.txt
cat ${pattern}_TS_file.txt | grep "|${DT}|" | grep ${pattern} | sort -r | head -1 > ${file}_f.txt
cat ${file}_f.txt >> ${file}_final_1.txt
dos2unix ${file}_final_1.txt ${file}_final.txt
}
paste
though, where in your case you need at least one regular file as input (unless you use process substitution, but not really useful in your case where${file}_only_${pattern}.txt
is used twice). (2) Creating temporary files in a temporary directory (mktemp -d
) allows you to remove them all by removing the directory (rm -r …
). // This is not an answer because (1) does not "get rid of creating all" and (2) is not "withoutrm
". – Kamil Maciorowski Aug 23 '22 at 15:03