How do i execute multiple commands sequentially on the command line?

Kamilski81

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

William Pursell

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I run multiple commands at once from windows command line using c++ / c?

From Dev

How do I execute a python script from the command line using custom commands?

From Dev

How do I execute a command in an iTerm window from the command line?

From Dev

How to add multiple commands in series in "Execute Windows Batch Command" in Jenkins

From Dev

How can I run multiple commands which have & in one command line?

From Dev

How do I easily rename multiple files using command line?

From Dev

How do I add multiple "+" commands into less from the command line

From Dev

How do I search my command-line history for commands I used before?

From Dev

How can I do the `history` command and not have line numbers so I can copy multiple line commands?

From Dev

How can I run multiple commands which have & in one command line?

From Dev

How do I easily rename multiple files using command line?

From Dev

How do I zip up multiple files on command line?

From Dev

How do I edit previous lines in a multiple line command in Bash?

From Dev

How can I run multiple commands at once from windows command line using c++ / c?

From Dev

How do I run multiple commands on one line in PowerShell?

From Dev

How do I search my command-line history for commands I used before?

From Dev

How do I write a command in vim to run multiple commands?

From Dev

How do I execute a python script from the command line using custom commands?

From Dev

How do I execute multiple commands when using find?

From Dev

What is 'execute:' on the command line, and how to I avoid it?

From Dev

How do I compile and link multiple files from the command line?

From Dev

How do I FTP multiple files from the command line?

From Dev

How do I execute multiple commands using the same argument?

From Dev

How do I add multiple "+" commands into less from the command line

From Dev

How do I open cmd with multiple startup parameters (I mean execute two commands when startup)?

From Dev

How do I open a new command line window from an sh script and then pass in multiple commands

From Dev

How can I execute multiple find commands in a single line?

From Dev

How do I execute FTP commands on one line?

From Dev

How to execute two commands sequentially

Related Related

  1. 1

    How can I run multiple commands at once from windows command line using c++ / c?

  2. 2

    How do I execute a python script from the command line using custom commands?

  3. 3

    How do I execute a command in an iTerm window from the command line?

  4. 4

    How to add multiple commands in series in "Execute Windows Batch Command" in Jenkins

  5. 5

    How can I run multiple commands which have & in one command line?

  6. 6

    How do I easily rename multiple files using command line?

  7. 7

    How do I add multiple "+" commands into less from the command line

  8. 8

    How do I search my command-line history for commands I used before?

  9. 9

    How can I do the `history` command and not have line numbers so I can copy multiple line commands?

  10. 10

    How can I run multiple commands which have & in one command line?

  11. 11

    How do I easily rename multiple files using command line?

  12. 12

    How do I zip up multiple files on command line?

  13. 13

    How do I edit previous lines in a multiple line command in Bash?

  14. 14

    How can I run multiple commands at once from windows command line using c++ / c?

  15. 15

    How do I run multiple commands on one line in PowerShell?

  16. 16

    How do I search my command-line history for commands I used before?

  17. 17

    How do I write a command in vim to run multiple commands?

  18. 18

    How do I execute a python script from the command line using custom commands?

  19. 19

    How do I execute multiple commands when using find?

  20. 20

    What is 'execute:' on the command line, and how to I avoid it?

  21. 21

    How do I compile and link multiple files from the command line?

  22. 22

    How do I FTP multiple files from the command line?

  23. 23

    How do I execute multiple commands using the same argument?

  24. 24

    How do I add multiple "+" commands into less from the command line

  25. 25

    How do I open cmd with multiple startup parameters (I mean execute two commands when startup)?

  26. 26

    How do I open a new command line window from an sh script and then pass in multiple commands

  27. 27

    How can I execute multiple find commands in a single line?

  28. 28

    How do I execute FTP commands on one line?

  29. 29

    How to execute two commands sequentially

HotTag

Archive