loop that prepends the filename to the beginning of each line in a tab separated file (thus generating a new column))
awk, bash, linux, sed
Solution
To insert filename at the begining of each line of each file, try something like:
awk '{print FILENAME, $0}' V*
`FILENAME` is a built-in variable that carries the name of the file. `V*` will glob to all the files in your directory.
If you wish to put a separator between the name and lines you can do:
awk '{print FILENAME " : " $0}' V*
Problem
I'm pretty new at this and try to loop over around 19000 files (all in one dir) in order to insert at the beginning of each line in each file the corresponding filename. I will later concatenate these files to get a file containing all the data i need for my analyses. File names show the following pattern: `V_foo_V_bar` The two `V_` parts in each filename are constant. the rest varies. I tried: ``` for f in V*; do awk '{print "$f" $} file ``` I did this with and without parentheses around `$f` and both didn't work. With parentheses the string `$f` is inserted to the file name Without paretheses nothing is inserted Help would be very much appreciated since I already tried a couple of other equally futile ideas of mine and frustration knocking on my door Thanks a lot.