Remove spaces except lines beginning with a specific pattern

text processing

I want to remove all spaces from a file, except from every line beginning with the same pattern (pattern is "ORGANISM").

Input:

Cat; Dog; Squirrel
ORGANISM Animalus terrus
Sequence: ACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGT

Output:

Cat;Dog;Squirrel
ORGANISM Animalus terrus
Sequence:ACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGT

No more spaces in any line except the line starting with the characters "ORGANISM".

Best Answer

sed '/^ORGANISM/!s/ //g' /path/to/input

This will remove all spaces on all lines that do not start with ORGANISM.

Related Question