I have thousands of similar files and I'd like to write their respective names after a pattern inside them. For example:**file 1's name is nexus0000inside the file there is:>Pseudomonas_1MATGATCCGCTTCGAGCAGGTCGGCAAACGCTATC>Pseudomonas_2MGTGAGCTTCGAGCAGGTCGGCGAGCCGCTATCand I want to get this:nexus0000>Pseudomonas_1MATGATCCGCTTCGAGCAGGTCGGCAAACGCTATCnexus0000>Pseudomonas_2MGTGAGCTTCGAGCAGGTCGGCGAGCCGCTATC**file 2's name is nexus0001inside the file there is:>Pseudomonas_1MATGATCCGCTTCGAGCAGGTCGGCAAACGCTATC>Pseudomonas_2MGTGAGCTTCGAGCAGGTCGGCGAGCCGCTATCand I want to get this:nexus0001>Pseudomonas_1MATGATCCGCTTCGAGCAGGTCGGCAAACGCTATCnexus0001>Pseudomonas_2MGTGAGCTTCGAGCAGGTCGGCGAGCCGCTATCetc.Up to this point, I've only managed to write the name of the file in the first line using: for file in nexus*; do echo $file$$(cat -- $file) > $file; doneThanks for the help!
Write name of file before a pattern inside that file
linux;bash;bioinformatics
sed solution:for f in nexus*; do sed -i s/^>/$f&/ $f; doneOr using gawk and its inplace extension (available since v. 4.1.0):for f in nexus*; do awk -i inplace '/^>/{ $0=FILENAME$0 }1' $f; done