Reputation: 23
I have a directory with thousands of csv files, each with 64 columns and 700+ lines. I would like to combine for importing into database tables.
Using cat, combining the files is no problem. However, each file represents a separate event, so when querying the database I would like to be able to extract just the lines from an individual file.
Is there a way to add an incrementing integer to each file before combing them?
for example:
log_file1
log_file2
to
log_file1
log_file2
Thanks
Upvotes: 1
Views: 115
Reputation: 246827
With awk, you could write:
awk 'FNR==1 {count++} {print count "," $0}' *.csv
That increments the "count" variable when the first record of each file is being processed.
Upvotes: 1