How do i execute multiple commands sequentially on the command line?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
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
command-line
add a comment |Â
up vote
1
down vote
favorite
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
command-line
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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
command-line
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
command-line
asked May 18 at 12:58
Kamilski81
1063
1063
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
2
down vote
That's not too simple to do if you're copy-pasting the commands to the terminal emulator. The problem here is that the terminal (that handles text input and display) is a distinct process from the shell (that prints your prompt and process the command line), and the terminal can't really know the meaning of the text you're pasting. So it can't wait for the previous command to finish, and for the shell to prompt again.
What you could do, would be to use set -v
or set -x
to have the shell print the commands as it runs them, or in that particular case, write a short shell loop to run the grep
s:
for pattern in 'type_of_record_new creating'
'type_of_record_modification found 1'
'type_of_record_modification found 0'
'type_of_record_inactivation found 1'
do
printf "%s:n%10d" "$pattern"
grep -c -e "$pattern" type_of_record.txt
done
That would give output like this
type_of_record_new creating: 469005
type_of_record_modification found 1: 9999
though the exact format could of course be modified. If you want the numbers on separate lines, and aligned to the right, you could use command substitution and printf %d
for the number of lines:
for pattern in ...
do
printf "%s:n%8dn" "$pattern" "$(grep -c -e "$pattern" type_of_record.txt)"
done
add a comment |Â
up vote
0
down vote
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.
add a comment |Â
up vote
0
down vote
Using echo
might do it
First, you would literally echo the command as a string, using single-quotes, then
Second, you would echo the command using double-quotes, which will execute the command
echo '$(date)'; echo "$(date)"
which gives
robert@pip2:/tmp$ echo '$(date)'; echo "$(date)"
$(date)
Fri May 18 07:30:27 PDT 2018
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
That's not too simple to do if you're copy-pasting the commands to the terminal emulator. The problem here is that the terminal (that handles text input and display) is a distinct process from the shell (that prints your prompt and process the command line), and the terminal can't really know the meaning of the text you're pasting. So it can't wait for the previous command to finish, and for the shell to prompt again.
What you could do, would be to use set -v
or set -x
to have the shell print the commands as it runs them, or in that particular case, write a short shell loop to run the grep
s:
for pattern in 'type_of_record_new creating'
'type_of_record_modification found 1'
'type_of_record_modification found 0'
'type_of_record_inactivation found 1'
do
printf "%s:n%10d" "$pattern"
grep -c -e "$pattern" type_of_record.txt
done
That would give output like this
type_of_record_new creating: 469005
type_of_record_modification found 1: 9999
though the exact format could of course be modified. If you want the numbers on separate lines, and aligned to the right, you could use command substitution and printf %d
for the number of lines:
for pattern in ...
do
printf "%s:n%8dn" "$pattern" "$(grep -c -e "$pattern" type_of_record.txt)"
done
add a comment |Â
up vote
2
down vote
That's not too simple to do if you're copy-pasting the commands to the terminal emulator. The problem here is that the terminal (that handles text input and display) is a distinct process from the shell (that prints your prompt and process the command line), and the terminal can't really know the meaning of the text you're pasting. So it can't wait for the previous command to finish, and for the shell to prompt again.
What you could do, would be to use set -v
or set -x
to have the shell print the commands as it runs them, or in that particular case, write a short shell loop to run the grep
s:
for pattern in 'type_of_record_new creating'
'type_of_record_modification found 1'
'type_of_record_modification found 0'
'type_of_record_inactivation found 1'
do
printf "%s:n%10d" "$pattern"
grep -c -e "$pattern" type_of_record.txt
done
That would give output like this
type_of_record_new creating: 469005
type_of_record_modification found 1: 9999
though the exact format could of course be modified. If you want the numbers on separate lines, and aligned to the right, you could use command substitution and printf %d
for the number of lines:
for pattern in ...
do
printf "%s:n%8dn" "$pattern" "$(grep -c -e "$pattern" type_of_record.txt)"
done
add a comment |Â
up vote
2
down vote
up vote
2
down vote
That's not too simple to do if you're copy-pasting the commands to the terminal emulator. The problem here is that the terminal (that handles text input and display) is a distinct process from the shell (that prints your prompt and process the command line), and the terminal can't really know the meaning of the text you're pasting. So it can't wait for the previous command to finish, and for the shell to prompt again.
What you could do, would be to use set -v
or set -x
to have the shell print the commands as it runs them, or in that particular case, write a short shell loop to run the grep
s:
for pattern in 'type_of_record_new creating'
'type_of_record_modification found 1'
'type_of_record_modification found 0'
'type_of_record_inactivation found 1'
do
printf "%s:n%10d" "$pattern"
grep -c -e "$pattern" type_of_record.txt
done
That would give output like this
type_of_record_new creating: 469005
type_of_record_modification found 1: 9999
though the exact format could of course be modified. If you want the numbers on separate lines, and aligned to the right, you could use command substitution and printf %d
for the number of lines:
for pattern in ...
do
printf "%s:n%8dn" "$pattern" "$(grep -c -e "$pattern" type_of_record.txt)"
done
That's not too simple to do if you're copy-pasting the commands to the terminal emulator. The problem here is that the terminal (that handles text input and display) is a distinct process from the shell (that prints your prompt and process the command line), and the terminal can't really know the meaning of the text you're pasting. So it can't wait for the previous command to finish, and for the shell to prompt again.
What you could do, would be to use set -v
or set -x
to have the shell print the commands as it runs them, or in that particular case, write a short shell loop to run the grep
s:
for pattern in 'type_of_record_new creating'
'type_of_record_modification found 1'
'type_of_record_modification found 0'
'type_of_record_inactivation found 1'
do
printf "%s:n%10d" "$pattern"
grep -c -e "$pattern" type_of_record.txt
done
That would give output like this
type_of_record_new creating: 469005
type_of_record_modification found 1: 9999
though the exact format could of course be modified. If you want the numbers on separate lines, and aligned to the right, you could use command substitution and printf %d
for the number of lines:
for pattern in ...
do
printf "%s:n%8dn" "$pattern" "$(grep -c -e "$pattern" type_of_record.txt)"
done
edited May 18 at 13:54
Jeff Schaller
31.1k846105
31.1k846105
answered May 18 at 13:30
ilkkachu
48.1k669133
48.1k669133
add a comment |Â
add a comment |Â
up vote
0
down vote
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.
add a comment |Â
up vote
0
down vote
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.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
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.
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.
edited May 18 at 14:01
answered May 18 at 13:56
William Pursell
2,01911111
2,01911111
add a comment |Â
add a comment |Â
up vote
0
down vote
Using echo
might do it
First, you would literally echo the command as a string, using single-quotes, then
Second, you would echo the command using double-quotes, which will execute the command
echo '$(date)'; echo "$(date)"
which gives
robert@pip2:/tmp$ echo '$(date)'; echo "$(date)"
$(date)
Fri May 18 07:30:27 PDT 2018
add a comment |Â
up vote
0
down vote
Using echo
might do it
First, you would literally echo the command as a string, using single-quotes, then
Second, you would echo the command using double-quotes, which will execute the command
echo '$(date)'; echo "$(date)"
which gives
robert@pip2:/tmp$ echo '$(date)'; echo "$(date)"
$(date)
Fri May 18 07:30:27 PDT 2018
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Using echo
might do it
First, you would literally echo the command as a string, using single-quotes, then
Second, you would echo the command using double-quotes, which will execute the command
echo '$(date)'; echo "$(date)"
which gives
robert@pip2:/tmp$ echo '$(date)'; echo "$(date)"
$(date)
Fri May 18 07:30:27 PDT 2018
Using echo
might do it
First, you would literally echo the command as a string, using single-quotes, then
Second, you would echo the command using double-quotes, which will execute the command
echo '$(date)'; echo "$(date)"
which gives
robert@pip2:/tmp$ echo '$(date)'; echo "$(date)"
$(date)
Fri May 18 07:30:27 PDT 2018
answered May 18 at 14:34
mrflash818
16117
16117
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f444594%2fhow-do-i-execute-multiple-commands-sequentially-on-the-command-line%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password