How to concatenate two command in shellWhat's the difference between <<, <<< and < < in...

Rationale to prefer local variables over instance variables?

Replacing tantalum capacitor with ceramic capacitor for Op Amps

Where do you go through passport control when transiting through another Schengen airport on your way out of the Schengen area?

A bug in Excel? Conditional formatting for marking duplicates also highlights unique value

Iron deposits mined from under the city

Computing the volume of a simplex-like object with constraints

Can you run a ground wire from stove directly to ground pole in the ground

Error in TransformedField

Ultrafilters as a double dual

What is better: yes / no radio, or simple checkbox?

What does "rhumatis" mean?

Can inspiration allow the Rogue to make a Sneak Attack?

Paper published similar to PhD thesis

Is being socially reclusive okay for a graduate student?

How to write a chaotic neutral protagonist and prevent my readers from thinking they are evil?

Does the in-code argument passing conventions used on PDP-11's have a name?

How to make sure I'm assertive enough in contact with subordinates?

Naming Characters after Friends/Family

Does the US political system, in principle, allow for a no-party system?

Is there such a thing in math the inverse of a sequence?

Deal the cards to the players

Is it a Cyclops number? "Nobody" knows!

I can't die. Who am I?

Do natural melee weapons (from racial traits) trigger Improved Divine Smite?



How to concatenate two command in shell


What's the difference between <<, <<< and < < in bash?Print out the amount of times 2 words appear in the syslog. But also have it tell me how many times for each hourremove file with -h_some_file_name in shellPutty SSH client command history?How do I access my Bash History?Concatenate two pathsShow other command line prompt in Midnight Commander (mc)How to restore sudo command after its having too many level of symlinkssearching for specialized patterns using grep in a json fileHow can I create a script file that opens and executes a command upon double-clicking?Measuring execution time of a command in milliseconds













6















I used to have this command to count how many times I have click with a mouse, the command is xev | grep "ButtonPress".



my colleague modify the command so that it return:



ButtonPress 0
ButtonPress 1
ButtonPress 2
ButtonPress 3


and so on... Unfortunately he's no longer contactable so I can't reach him anymore.



I recall the involvement of i++ and something like that, how to reproduce the command?










share|improve this question







New contributor




Jackie Nelson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Do you mean xev | grep -c "ButtonPress", showing the number of clicks on exit?

    – dessert
    21 hours ago











  • It shows ButtonPress + number everytime I click on white box pop up window, sorry I'm a novice...

    – Jackie Nelson
    21 hours ago











  • dessert, your command worked but it only return the number when I exit xev. How to make it return live value ?

    – Jackie Nelson
    21 hours ago
















6















I used to have this command to count how many times I have click with a mouse, the command is xev | grep "ButtonPress".



my colleague modify the command so that it return:



ButtonPress 0
ButtonPress 1
ButtonPress 2
ButtonPress 3


and so on... Unfortunately he's no longer contactable so I can't reach him anymore.



I recall the involvement of i++ and something like that, how to reproduce the command?










share|improve this question







New contributor




Jackie Nelson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Do you mean xev | grep -c "ButtonPress", showing the number of clicks on exit?

    – dessert
    21 hours ago











  • It shows ButtonPress + number everytime I click on white box pop up window, sorry I'm a novice...

    – Jackie Nelson
    21 hours ago











  • dessert, your command worked but it only return the number when I exit xev. How to make it return live value ?

    – Jackie Nelson
    21 hours ago














6












6








6


1






I used to have this command to count how many times I have click with a mouse, the command is xev | grep "ButtonPress".



my colleague modify the command so that it return:



ButtonPress 0
ButtonPress 1
ButtonPress 2
ButtonPress 3


and so on... Unfortunately he's no longer contactable so I can't reach him anymore.



I recall the involvement of i++ and something like that, how to reproduce the command?










share|improve this question







New contributor




Jackie Nelson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I used to have this command to count how many times I have click with a mouse, the command is xev | grep "ButtonPress".



my colleague modify the command so that it return:



ButtonPress 0
ButtonPress 1
ButtonPress 2
ButtonPress 3


and so on... Unfortunately he's no longer contactable so I can't reach him anymore.



I recall the involvement of i++ and something like that, how to reproduce the command?







command-line bash scripts dash-shell






share|improve this question







New contributor




Jackie Nelson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Jackie Nelson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Jackie Nelson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 21 hours ago









Jackie NelsonJackie Nelson

334




334




New contributor




Jackie Nelson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Jackie Nelson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Jackie Nelson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • Do you mean xev | grep -c "ButtonPress", showing the number of clicks on exit?

    – dessert
    21 hours ago











  • It shows ButtonPress + number everytime I click on white box pop up window, sorry I'm a novice...

    – Jackie Nelson
    21 hours ago











  • dessert, your command worked but it only return the number when I exit xev. How to make it return live value ?

    – Jackie Nelson
    21 hours ago



















  • Do you mean xev | grep -c "ButtonPress", showing the number of clicks on exit?

    – dessert
    21 hours ago











  • It shows ButtonPress + number everytime I click on white box pop up window, sorry I'm a novice...

    – Jackie Nelson
    21 hours ago











  • dessert, your command worked but it only return the number when I exit xev. How to make it return live value ?

    – Jackie Nelson
    21 hours ago

















Do you mean xev | grep -c "ButtonPress", showing the number of clicks on exit?

– dessert
21 hours ago





Do you mean xev | grep -c "ButtonPress", showing the number of clicks on exit?

– dessert
21 hours ago













It shows ButtonPress + number everytime I click on white box pop up window, sorry I'm a novice...

– Jackie Nelson
21 hours ago





It shows ButtonPress + number everytime I click on white box pop up window, sorry I'm a novice...

– Jackie Nelson
21 hours ago













dessert, your command worked but it only return the number when I exit xev. How to make it return live value ?

– Jackie Nelson
21 hours ago





dessert, your command worked but it only return the number when I exit xev. How to make it return live value ?

– Jackie Nelson
21 hours ago










1 Answer
1






active

oldest

votes


















10














The fact that there's i++ suggests there was either bash or ksh shell in use,potentially awk or perl as well. In either case, we can use process substitution <(...) to feed output of xev to counting loop (although simple pipeline xev | while... could work just fine).



text processing tools:



Portably and for fewer key strokes we can use awk :



$ xev | awk '/ButtonPress/{print "ButtonPress",i++}'
ButtonPress 0
ButtonPress 1
ButtonPress 2
ButtonPress 3


perl version:



$ xev | perl -ne '/ButtonPress/ && printf("ButtonPress:%dn",++$i)'
ButtonPress:1
ButtonPress:2
ButtonPress:3


Shells:



Here's what works in bash:



$ i=0; while IFS= read -r line; do [[ $line =~ ButtonPress ]] && { ((i++)); printf 'ButtonPress: %dn' "$i";} ;done < <(xev)
ButtonPress: 1
ButtonPress: 2
ButtonPress: 3


In case you don't want spammy output of many lines, we can use printf to send control code to clear previous line and output only the running count (that is you'd only see integer value change on the line):



$ i=0; while IFS= read -r line; do [[ $line =~ ButtonPress ]] && { ((i++)); printf "r%b" "33[2K"; printf 'ButtonPress: %d' "$i";} ;done < <(xev)


Portably in POSIX shell:



$ xev | ( i=0; while IFS= read -r l; do case "$l" in  *ButtonPress*) i=$((i+1)) && printf 'ButtonPress:%dn' "$i";;  esac ;done)
ButtonPress:1
ButtonPress:2
ButtonPress:3


basic utils:



For simple, quick, and dirty way we can hack this via cat -n with line count being printed on the left instead of right:



$ xev | grep --line-buffered 'ButtonPress' | cat -n
1 ButtonPress event, serial 34, synthetic NO, window 0x4a00001,
2 ButtonPress event, serial 34, synthetic NO, window 0x4a00001,
3 ButtonPress event, serial 34, synthetic NO, window 0x4a00001,





share|improve this answer


























  • I tried your first command that has awk in it, it works but there's a bit of lag when the output return

    – Jackie Nelson
    21 hours ago











  • However, your second and third command works perfectly, thanks a lot Sergiy

    – Jackie Nelson
    21 hours ago











  • @JackieNelson A bit of lag might suggest buffering, which may be related to another awk version in use. Recent Ubuntu uses gawk and before 16.04 default was mawk IIRC. Regardless, glad I could help :)

    – Sergiy Kolodyazhnyy
    21 hours ago











  • Can you make so that the number start from one on perl version ? Not zero

    – Jackie Nelson
    21 hours ago











  • @JackieNelson Yep, already changed that

    – Sergiy Kolodyazhnyy
    21 hours ago











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Jackie Nelson is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1123723%2fhow-to-concatenate-two-command-in-shell%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









10














The fact that there's i++ suggests there was either bash or ksh shell in use,potentially awk or perl as well. In either case, we can use process substitution <(...) to feed output of xev to counting loop (although simple pipeline xev | while... could work just fine).



text processing tools:



Portably and for fewer key strokes we can use awk :



$ xev | awk '/ButtonPress/{print "ButtonPress",i++}'
ButtonPress 0
ButtonPress 1
ButtonPress 2
ButtonPress 3


perl version:



$ xev | perl -ne '/ButtonPress/ && printf("ButtonPress:%dn",++$i)'
ButtonPress:1
ButtonPress:2
ButtonPress:3


Shells:



Here's what works in bash:



$ i=0; while IFS= read -r line; do [[ $line =~ ButtonPress ]] && { ((i++)); printf 'ButtonPress: %dn' "$i";} ;done < <(xev)
ButtonPress: 1
ButtonPress: 2
ButtonPress: 3


In case you don't want spammy output of many lines, we can use printf to send control code to clear previous line and output only the running count (that is you'd only see integer value change on the line):



$ i=0; while IFS= read -r line; do [[ $line =~ ButtonPress ]] && { ((i++)); printf "r%b" "33[2K"; printf 'ButtonPress: %d' "$i";} ;done < <(xev)


Portably in POSIX shell:



$ xev | ( i=0; while IFS= read -r l; do case "$l" in  *ButtonPress*) i=$((i+1)) && printf 'ButtonPress:%dn' "$i";;  esac ;done)
ButtonPress:1
ButtonPress:2
ButtonPress:3


basic utils:



For simple, quick, and dirty way we can hack this via cat -n with line count being printed on the left instead of right:



$ xev | grep --line-buffered 'ButtonPress' | cat -n
1 ButtonPress event, serial 34, synthetic NO, window 0x4a00001,
2 ButtonPress event, serial 34, synthetic NO, window 0x4a00001,
3 ButtonPress event, serial 34, synthetic NO, window 0x4a00001,





share|improve this answer


























  • I tried your first command that has awk in it, it works but there's a bit of lag when the output return

    – Jackie Nelson
    21 hours ago











  • However, your second and third command works perfectly, thanks a lot Sergiy

    – Jackie Nelson
    21 hours ago











  • @JackieNelson A bit of lag might suggest buffering, which may be related to another awk version in use. Recent Ubuntu uses gawk and before 16.04 default was mawk IIRC. Regardless, glad I could help :)

    – Sergiy Kolodyazhnyy
    21 hours ago











  • Can you make so that the number start from one on perl version ? Not zero

    – Jackie Nelson
    21 hours ago











  • @JackieNelson Yep, already changed that

    – Sergiy Kolodyazhnyy
    21 hours ago
















10














The fact that there's i++ suggests there was either bash or ksh shell in use,potentially awk or perl as well. In either case, we can use process substitution <(...) to feed output of xev to counting loop (although simple pipeline xev | while... could work just fine).



text processing tools:



Portably and for fewer key strokes we can use awk :



$ xev | awk '/ButtonPress/{print "ButtonPress",i++}'
ButtonPress 0
ButtonPress 1
ButtonPress 2
ButtonPress 3


perl version:



$ xev | perl -ne '/ButtonPress/ && printf("ButtonPress:%dn",++$i)'
ButtonPress:1
ButtonPress:2
ButtonPress:3


Shells:



Here's what works in bash:



$ i=0; while IFS= read -r line; do [[ $line =~ ButtonPress ]] && { ((i++)); printf 'ButtonPress: %dn' "$i";} ;done < <(xev)
ButtonPress: 1
ButtonPress: 2
ButtonPress: 3


In case you don't want spammy output of many lines, we can use printf to send control code to clear previous line and output only the running count (that is you'd only see integer value change on the line):



$ i=0; while IFS= read -r line; do [[ $line =~ ButtonPress ]] && { ((i++)); printf "r%b" "33[2K"; printf 'ButtonPress: %d' "$i";} ;done < <(xev)


Portably in POSIX shell:



$ xev | ( i=0; while IFS= read -r l; do case "$l" in  *ButtonPress*) i=$((i+1)) && printf 'ButtonPress:%dn' "$i";;  esac ;done)
ButtonPress:1
ButtonPress:2
ButtonPress:3


basic utils:



For simple, quick, and dirty way we can hack this via cat -n with line count being printed on the left instead of right:



$ xev | grep --line-buffered 'ButtonPress' | cat -n
1 ButtonPress event, serial 34, synthetic NO, window 0x4a00001,
2 ButtonPress event, serial 34, synthetic NO, window 0x4a00001,
3 ButtonPress event, serial 34, synthetic NO, window 0x4a00001,





share|improve this answer


























  • I tried your first command that has awk in it, it works but there's a bit of lag when the output return

    – Jackie Nelson
    21 hours ago











  • However, your second and third command works perfectly, thanks a lot Sergiy

    – Jackie Nelson
    21 hours ago











  • @JackieNelson A bit of lag might suggest buffering, which may be related to another awk version in use. Recent Ubuntu uses gawk and before 16.04 default was mawk IIRC. Regardless, glad I could help :)

    – Sergiy Kolodyazhnyy
    21 hours ago











  • Can you make so that the number start from one on perl version ? Not zero

    – Jackie Nelson
    21 hours ago











  • @JackieNelson Yep, already changed that

    – Sergiy Kolodyazhnyy
    21 hours ago














10












10








10







The fact that there's i++ suggests there was either bash or ksh shell in use,potentially awk or perl as well. In either case, we can use process substitution <(...) to feed output of xev to counting loop (although simple pipeline xev | while... could work just fine).



text processing tools:



Portably and for fewer key strokes we can use awk :



$ xev | awk '/ButtonPress/{print "ButtonPress",i++}'
ButtonPress 0
ButtonPress 1
ButtonPress 2
ButtonPress 3


perl version:



$ xev | perl -ne '/ButtonPress/ && printf("ButtonPress:%dn",++$i)'
ButtonPress:1
ButtonPress:2
ButtonPress:3


Shells:



Here's what works in bash:



$ i=0; while IFS= read -r line; do [[ $line =~ ButtonPress ]] && { ((i++)); printf 'ButtonPress: %dn' "$i";} ;done < <(xev)
ButtonPress: 1
ButtonPress: 2
ButtonPress: 3


In case you don't want spammy output of many lines, we can use printf to send control code to clear previous line and output only the running count (that is you'd only see integer value change on the line):



$ i=0; while IFS= read -r line; do [[ $line =~ ButtonPress ]] && { ((i++)); printf "r%b" "33[2K"; printf 'ButtonPress: %d' "$i";} ;done < <(xev)


Portably in POSIX shell:



$ xev | ( i=0; while IFS= read -r l; do case "$l" in  *ButtonPress*) i=$((i+1)) && printf 'ButtonPress:%dn' "$i";;  esac ;done)
ButtonPress:1
ButtonPress:2
ButtonPress:3


basic utils:



For simple, quick, and dirty way we can hack this via cat -n with line count being printed on the left instead of right:



$ xev | grep --line-buffered 'ButtonPress' | cat -n
1 ButtonPress event, serial 34, synthetic NO, window 0x4a00001,
2 ButtonPress event, serial 34, synthetic NO, window 0x4a00001,
3 ButtonPress event, serial 34, synthetic NO, window 0x4a00001,





share|improve this answer















The fact that there's i++ suggests there was either bash or ksh shell in use,potentially awk or perl as well. In either case, we can use process substitution <(...) to feed output of xev to counting loop (although simple pipeline xev | while... could work just fine).



text processing tools:



Portably and for fewer key strokes we can use awk :



$ xev | awk '/ButtonPress/{print "ButtonPress",i++}'
ButtonPress 0
ButtonPress 1
ButtonPress 2
ButtonPress 3


perl version:



$ xev | perl -ne '/ButtonPress/ && printf("ButtonPress:%dn",++$i)'
ButtonPress:1
ButtonPress:2
ButtonPress:3


Shells:



Here's what works in bash:



$ i=0; while IFS= read -r line; do [[ $line =~ ButtonPress ]] && { ((i++)); printf 'ButtonPress: %dn' "$i";} ;done < <(xev)
ButtonPress: 1
ButtonPress: 2
ButtonPress: 3


In case you don't want spammy output of many lines, we can use printf to send control code to clear previous line and output only the running count (that is you'd only see integer value change on the line):



$ i=0; while IFS= read -r line; do [[ $line =~ ButtonPress ]] && { ((i++)); printf "r%b" "33[2K"; printf 'ButtonPress: %d' "$i";} ;done < <(xev)


Portably in POSIX shell:



$ xev | ( i=0; while IFS= read -r l; do case "$l" in  *ButtonPress*) i=$((i+1)) && printf 'ButtonPress:%dn' "$i";;  esac ;done)
ButtonPress:1
ButtonPress:2
ButtonPress:3


basic utils:



For simple, quick, and dirty way we can hack this via cat -n with line count being printed on the left instead of right:



$ xev | grep --line-buffered 'ButtonPress' | cat -n
1 ButtonPress event, serial 34, synthetic NO, window 0x4a00001,
2 ButtonPress event, serial 34, synthetic NO, window 0x4a00001,
3 ButtonPress event, serial 34, synthetic NO, window 0x4a00001,






share|improve this answer














share|improve this answer



share|improve this answer








edited 21 hours ago

























answered 21 hours ago









Sergiy KolodyazhnyySergiy Kolodyazhnyy

73.7k9154322




73.7k9154322













  • I tried your first command that has awk in it, it works but there's a bit of lag when the output return

    – Jackie Nelson
    21 hours ago











  • However, your second and third command works perfectly, thanks a lot Sergiy

    – Jackie Nelson
    21 hours ago











  • @JackieNelson A bit of lag might suggest buffering, which may be related to another awk version in use. Recent Ubuntu uses gawk and before 16.04 default was mawk IIRC. Regardless, glad I could help :)

    – Sergiy Kolodyazhnyy
    21 hours ago











  • Can you make so that the number start from one on perl version ? Not zero

    – Jackie Nelson
    21 hours ago











  • @JackieNelson Yep, already changed that

    – Sergiy Kolodyazhnyy
    21 hours ago



















  • I tried your first command that has awk in it, it works but there's a bit of lag when the output return

    – Jackie Nelson
    21 hours ago











  • However, your second and third command works perfectly, thanks a lot Sergiy

    – Jackie Nelson
    21 hours ago











  • @JackieNelson A bit of lag might suggest buffering, which may be related to another awk version in use. Recent Ubuntu uses gawk and before 16.04 default was mawk IIRC. Regardless, glad I could help :)

    – Sergiy Kolodyazhnyy
    21 hours ago











  • Can you make so that the number start from one on perl version ? Not zero

    – Jackie Nelson
    21 hours ago











  • @JackieNelson Yep, already changed that

    – Sergiy Kolodyazhnyy
    21 hours ago

















I tried your first command that has awk in it, it works but there's a bit of lag when the output return

– Jackie Nelson
21 hours ago





I tried your first command that has awk in it, it works but there's a bit of lag when the output return

– Jackie Nelson
21 hours ago













However, your second and third command works perfectly, thanks a lot Sergiy

– Jackie Nelson
21 hours ago





However, your second and third command works perfectly, thanks a lot Sergiy

– Jackie Nelson
21 hours ago













@JackieNelson A bit of lag might suggest buffering, which may be related to another awk version in use. Recent Ubuntu uses gawk and before 16.04 default was mawk IIRC. Regardless, glad I could help :)

– Sergiy Kolodyazhnyy
21 hours ago





@JackieNelson A bit of lag might suggest buffering, which may be related to another awk version in use. Recent Ubuntu uses gawk and before 16.04 default was mawk IIRC. Regardless, glad I could help :)

– Sergiy Kolodyazhnyy
21 hours ago













Can you make so that the number start from one on perl version ? Not zero

– Jackie Nelson
21 hours ago





Can you make so that the number start from one on perl version ? Not zero

– Jackie Nelson
21 hours ago













@JackieNelson Yep, already changed that

– Sergiy Kolodyazhnyy
21 hours ago





@JackieNelson Yep, already changed that

– Sergiy Kolodyazhnyy
21 hours ago










Jackie Nelson is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















Jackie Nelson is a new contributor. Be nice, and check out our Code of Conduct.













Jackie Nelson is a new contributor. Be nice, and check out our Code of Conduct.












Jackie Nelson is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1123723%2fhow-to-concatenate-two-command-in-shell%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...

Tribunal Administrativo e Fiscal de Mirandela Referências Menu de...

looking for continuous Screen Capture for retroactivly reproducing errors, timeback machineRolling desktop...