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
  • 6,009
  • 13
  • 57
  • 77

1 Answers1

8

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
  • 349,597
  • 67
  • 533
  • 578
anubhava
  • 761,203
  • 64
  • 569
  • 643