I have a bash script. If I run this command to:
- grep for certain patterns,
- transform the output,
- sort the output
- dedupe the output
then I get one grep find per line in terminal
LC_ALL=C grep -o --color -h -E -C 0 -r "$pattern" /pathto/Pre_N/ | tr -d '[:digit:]' | sort | uniq
However, if I put it in an output variable then the formatting is lost (upon echoing to a file or echoing on screen).
#!/usr/bin/env bash
output=$(LC_ALL=C grep -o --color -h -E -C 0 -r "$pattern" /pathto/Pre_N/ | tr -d '[:digit:]' | sort | uniq)
echo $output > $fn
How can I preserve the formatting of the out put of this command once I save it to a variable?