1

There are multiple files:

1.csv
2.csv
...

With some generic content like:

[1.csv]
a
b
c

[2.csv]
d
e
f

I want to concatenate the content of the files into one file, but with the filename on every line. So the result should look something like:

[concatenated.csv]
1.csv;a
1.csv;b
1.csv;c
2.csv;d
2.csv;e
2.csv;f
Kiril
  • 5,437
  • 12
  • 52
  • 75

1 Answers1

7

You can use awk:

awk -v OFS=';' '{print FILENAME, $0}' *.csv

1.csv;a
1.csv;b
1.csv;c
2.csv;d
2.csv;e
2.csv;f
John Kugelman
  • 330,190
  • 66
  • 504
  • 555
anubhava
  • 713,503
  • 59
  • 514
  • 593