I have 2 files file_A and file_B. The file file_A contains file name and then after space the code line. This code line can have random kind of characters say blanks,: etc. It looks like this. Please note that the code line in the file is not surrounded by (). This was only for illustration purpose.
bash$ cat file_A
file_name1 (code line a)
file_name1 (code line b)
file_name2 (code line c)
file_name2 (code line d)
file_name2 (code line e)
The file file_B contains the file_name along with frequency in file_A
bash$cat file_B
file_name1 2
file_name2 3
I want output as: (frequency,file_name,code_line)
2 file_name1 (code line a)
2 file_name1 (code line b)
3 file_name2 (code line c)
3 file_name2 (code line d)
3 file_name2 (code line e)
bash$ join -1 1 -2 1 file_B file_A > file_C
I get file_C as (I get join fields as 1st field)
file_name1 2 (code line a)
file_name1 2 (code line b)
file_name2 3 (code line c)
file_name2 3 (code line d)
file_name2 3 (code line e)
How do I get the frequency field in the 1st field?.
I know that with join I can use -o format and mention what fields and in what order I want in the output. But how do I say that put all in the code line (which can contain anything, so no delimiter as such) as such
Thanks,
Note: Maybe you will have to escape the normal brackets with backspaces to make it work.
Note join doesn't support specifying a range of fields in the output format, so the following is a bit hacky, but does support up to 8 spaces in the "code line"