I am writing a simple script in tcsh (apparently that's a bad idea, but well) to grep some patterns from a text file. Say we have a file animal_names.txt
which consists of:
dog carrot
dog bolt
cat larry
cat brownies
bird parry
bird pirate
and I wrote the script:
set animals = "dog\|cat"
set names = `grep $animals animal_names.txt`
echo "$names"
The intention was to grep all lines with "dog" or "cat". However, the output I get is just oneline:
dog carrot dog bolt cat larry cat brownies
Somehow the newlines were removed at the output. Is there a way to keep the newlines? Another post suggested to use the :q modifier, but it doesn't work in my case.