I am pasting multiple commands into my command line and would like each line to execute and output the results sequentially.
I am pasting my input:
cat type_of_record.txt | grep 'type_of_record_new creating' | wc -l
cat type_of_record.txt | grep 'type_of_record_modification found 1' | wc -l
cat type_of_record.txt | grep 'type_of_record_modification found 0' | wc -l
cat type_of_record.txt | grep 'type_of_record_inactivation found 1' | wc -l
and getting output:
469005
9999
5099
25
But instead, would like each command to execute after each line break and have my output look like:
cat type_of_record.txt | grep 'type_of_record_modification found 1' | wc -l
469005
cat type_of_record.txt | grep 'type_of_record_modification found 0' | wc -l
9999
cat type_of_record.txt | grep 'type_of_record_inactivation found 1' | wc -l
5099
Not sure if this is possible but it would save me a lot of time if I don't have to map each result back to the line where it came from
Just paste your clipboard into a heredoc:
$ sh -v << EOF
> cat type_of_record.txt | grep 'type_of_record_new creating' | wc -l
> cat type_of_record.txt | grep 'type_of_record_modification found 1' | wc -l
> cat type_of_record.txt | grep 'type_of_record_modification found 0' | wc -l
> cat type_of_record.txt | grep 'type_of_record_inactivation found 1' | wc -l
> EOF
cat type_of_record.txt | grep 'type_of_record_new creating' | wc -l
cat: type_of_record.txt: No such file or directory
0
cat type_of_record.txt | grep 'type_of_record_modification found 1' | wc -l
cat: type_of_record.txt: No such file or directory
0
cat type_of_record.txt | grep 'type_of_record_modification found 0' | wc -l
cat: type_of_record.txt: No such file or directory
0
cat type_of_record.txt | grep 'type_of_record_inactivation found 1' | wc -l
cat: type_of_record.txt: No such file or directory
0
In the above, I typed 'sh -v << EOF', then pasted the code from your question into the terminal, and then hit return and typed 'EOF'. If you do this sort of thing, make sure you carefully review the text you're pasting. You will probably want to quote the delimiter (eg sh << 'EOF'
) to avoid interpolation of any of the pasted text, but that's not necessary in this case.
But note that in this particular case, it seems better to use awk to count the matching records so that you only need to make one pass through the file.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments