Pages

Saturday, March 20, 2021


Command in script

awk '{print >> ( $3 ".txt")}' filename
Input file

sample_text1 text3 20190426
sample_text2 text4 20190426
text1 abc 20190425
text2 def 20190425
generated output's (20190426.txt and 20190425.txt)

20190426.txt

sample_text1 text3 20190426
sample_text2 text4 20190426

20190425.txt

text1 abc 20190425
text2 def 20190425


You can change print to print $1 – steeldriver Apr 27 '19 at 1:41
i want to create output file based on third fields but in output can we have only $1 – upkar Apr 27 '19 at 1:42    


Got the answer now. As the 3rd field holds the essential part of the target file name, the latter is contructed from it and then used for the redirection of the print statement, which by default prints $0, the entire input line