Skip to main content
NR is already incremented for every record, no need for an extra variable.
Source Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k
awk '{print $0 > $0".txt" }'  inputfile

would create one file per unique line in inputfile named after the content of those lines (with a .txt extension). But beware that when the limit of concurrent open files is reached, some awk implementations will fail.

Or

awk '{print $0f >= "output_file." NRNR; print $0 > f; close(f)}' inputfile

To have numbered output files.

awk '{print $0 > $0".txt" }'  inputfile

Or

awk '{print $0 > "output_file." NR }' inputfile
awk '{print > $0".txt" }'  inputfile

would create one file per unique line in inputfile named after the content of those lines (with a .txt extension). But beware that when the limit of concurrent open files is reached, some awk implementations will fail.

Or

awk '{f = "output_file." NR; print $0 > f; close(f)}' inputfile

To have numbered output files.

NR is already incremented for every record, no need for an extra variable.
Source Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k
awk '{print $0 > $0".txt" }'  inputfile

Or

awk '{i++}{print $0 > "output_file."i" NR }' inputfile
awk '{print $0 > $0".txt" }'  inputfile

Or

awk '{i++}{print $0 > "output_file."i }' inputfile
awk '{print $0 > $0".txt" }'  inputfile

Or

awk '{print $0 > "output_file." NR }' inputfile
added 1 characters in body
Source Link
Rahul Patil
  • 25.6k
  • 26
  • 85
  • 96
awk '{print $0 > $0".txt" }'  inputfile

Or

awk '{i++}{print $0 > "output_file."i }' test.txtinputfile
awk '{print $0 > $0".txt" }'  inputfile

Or

awk '{i++}{print $0 > "output_file."i }' test.txt
awk '{print $0 > $0".txt" }'  inputfile

Or

awk '{i++}{print $0 > "output_file."i }' inputfile
Source Link
Rahul Patil
  • 25.6k
  • 26
  • 85
  • 96
Loading