Sorry if this is a repeat question; I am very green with unix.
I have several (n = 12) text files that contain spaces in the first column that should all be changed to underscores. The files are of phylogeny ID and counts in different samples, see example below.
phylodist all_Tg_3300056613 all_Tg_3300056890 all_Tg_3300057214 all_Tg_3300057270 all_Tg_3300057271
Archaea;Candidatus Diapherotrites;unclassified Candidatus Diapherotrites;unclassified Candidatus Diapherotrites;unclassified Candidatus Diapherotrites;Candidatus Iainarchaeum;Candidatus Iainarchaeum andersonii;Candidatus Iainarchaeum andersonii SCGC AAA011-E11 (contamination screened) 5.91123918323401 12.3266217289478 2.01841255189448 0 0
Archaea;Candidatus Korarchaeota;unclassified Candidatus Korarchaeota;unclassified Candidatus Korarchaeota;unclassified Candidatus Korarchaeota;Candidatus Korarchaeum;Candidatus Korarchaeum cryptofilum;Candidatus Korarchaeum cryptofilum OPF8 419.386679750923 502.442103336035 446.524450581103 0 0
Archaea;Candidatus Micrarchaeota;unclassified Candidatus Micrarchaeota;unclassified Candidatus Micrarchaeota;unclassified Candidatus Micrarchaeota;Candidatus Mancarchaeum;Candidatus Mancarchaeum acidiphilum;Candidatus Mancarchaeum acidiphilum Mia14 7.5272438877384 4.95622132293645 0 0 0
Archaea;Candidatus Thermoplasmatota;Candidatus Poseidoniia;Candidatus Poseidoniales;unclassified Candidatus Poseidoniales;unclassified Candidatus Poseidoniales;uncultured Candidatus Poseidoniales archaeon;Candidatus Poseidoniales archaeon AHCG 5.15021284928401 6.49674226828345 0 0 0
My goal is to upload the files to R as a DESeq2 object, separated by ";". What is a simple way to process all my files?
CodePudding user response:
Use the sed
command:
sed -i 's/ /_/' *.txt
Since there's no g
modifier in the substitute command, this will replace just the first space in each line with an underscore.