Wednesday, October 5, 2022

[SOLVED] Cat all files and add a tag as the file name before a character

Issue

Hello everyone I have seevral files such as

FILE1
>content
AGGAGAjg
GAUGAUGUG
AAG
FILE2
>Againontent
HDHDIHD
DHHDDHK
DH

and I would like to cat all those files into one unique using cat FILE* >> Unique_file

but also to add the name of the file just before the > in each file.

then the content of the Unique_file would be :

>FILE1_content
AGGAGAjg
GAUGAUGUG
AAG
>FILE2_Againontent
HDHDIHD
DHHDDHK
DH

Solution

for file in $(ls FILE*); do echo $file >> unique_file; cat $file >> unique_file; done

This will echo the file name and append it to the output file before appending the contents of the file itself.



Answered By - Chinork
Answer Checked By - Timothy Miller (WPSolving Admin)