0

I am needing a Unix script to get and concat all the filenames in a path/folder with the first line in each file.

Example there is a location /bin/etc/target and there are 3 files in it

file1.csv
header,2

file2.csv
header,3

file3.csv
header,4

My output should be

file1.csv,header,2
file2.csv,header,3
file3.csv,header,4

I need a command that gives me this value from the root because I am using another tool to get this output from this location.

I have a sample command awk '{print FILENAME "," $0; nextfile}' * which works if I am in the directory. It just does not work from the root. I want this command to do something like below

cd /bin/etc/target
awk '{print FILENAME "," $0; nextfile}' *
Nic3500
  • 8,144
  • 10
  • 29
  • 40
sunny
  • 3
  • 2

1 Answers1

0

Since you tagged DataStage, I assume you want to read the data with a parallel job.

Instead of distracting future developers in your project with shell voodoo (SCNR), you can just use the Sequential File Stage to read the files.

If you choose to select the files by pattern, the stage has an option to put the filename into a new column. If all files do have the same schema, you can load all files in one step including a column for filenames and also one for the line number.

Justus Kenklies
  • 440
  • 3
  • 10