I am using a CLI application that prints \u001Bc to the terminal to clear the screen. This application is not interactive, though, and I would like to see all of its output. Is there a way to prevent this application from clearing the screen without altering its source code?
I attempted to use app | grep -v '\u001Bc' but this doesn't appear to work, and it would also filter out the entire line containing \u001Bc even if it did work.
You can try removing the Esc + c via sed
application | sed 's/\x1bc//g'
Related
I'm having troubles in doing simple stuff with grep in my Mac. I'd like to rename a file, and for that I use grep and sed.
If I don't use grep, it works fine.
If I use grep, it doesn't work: mv shows a weird error.
For what I understand, the reason may be the colored grep I am using, and then mv uses not the filename, but the code for displaying the colored filename in the console (as elm content is a colored yum.txt, instead of a normal one).
Is this the reason? What can I do?
You are right, those strange characters are indeed color codes. You can search for the --color= option either in GREP_OPTIONS environment variable (printenv) and/or your user defined aliases.
Then just change --color=always to --color=auto; with the --color=auto option set, grep should display color codes only when the standard output is connected to a terminal and plain text otherwise.
I am trying to use output from a built in command in a firewall vendor. The script shows important information using watch.
However I need to make watch stop after it has outputed the data.
I have tried to cat the file, removing watch from the file but it doesn't work very well.
Perhaps I can send it a Ctrl + C right away using echo? I have done something similar on another interactive script, where I did: echo -e "2\nQ" | command to make it select number 2, then press Q to make it quit.
Any other ideas to make watch die after it has shown the data?
I've been searching and never found an answer that works for me.
Specifically, I want to see logcat outputs from a specific application.
I'm not using eclipse, I'm using command line adb logcat.
I'm only given the apk build of the application, so I don't know any tags to use the filter by tags everyone has been talking about. I don't think I can just go in and add tags or what not.
I saw in another page someone suggested
"Use ps/grep/cut to grab the PID, then grep for logcat entries with that PID. Here's the command I use:"
adb logcat | grep `adb shell ps | grep com.example.package | cut -c10-15`
This doesn't work for me either.
Maybe you are using this in windows?
If I have a job running in the background, like a very specific grep on a tail of a file, i.e. tail -f /var/log/syslog | grep -i failure, output from that command is printed to my terminal, thereby breaking up whatever I'm typing.
This is equivalent to "logging synchronous" in a "vty" or "con" line in a Cisco router. I know in a Cisco appliance, if "logging synchronous" isn't enabled and you are typing on the terminal, anything that spits out to the terminal interrupts what you're typing. If you enable "logging synchronous" on your terminal, the message is still spit out but the command string you had been typing is restored immediately to the next line.
In BASH, I though there was a key combination that would restore the command string that was being typed but I can't recall or find out what that key combination is.
The line you were typing is unaltered by output. The only problem is that you can't see it anymore.
There is a readline command, redraw-current-line, which will do just as it says, redraw the current line. By default, bash doesn't bind that command to any key sequence, which makes it a bit awkward to use. Bash binds Ctrl+L to the clear-screen command, which will also redraw the current line, but its side-effect of clearing the screen can be a bit unwelcome.
If you want to enable this feature, you'll need to find some key sequence to bind the command to. For example, you could bind Ctrl+L to redraw-current-line and use EscCtrl+L for clear-screen. To do that:
bind '"\C-l"':redraw-current-line
bind '"\e\C-l"':clear-screen
Of course, that's just for experimentation; it will only have effect in the current terminal session. You'll need to put that into your bash startup file for it to be sticky.
I usually press Ctrl+L. The disadvantage is it also clears the screen.
My personal solution to that problem is to redirect the output of the background job to a file, eg.
tail -f /var/log/syslog | grep -i failure > foo.myout
I'm assuming that's not possible for some reason. Have you tried control-p?
So I am on an old (fully aluminum) macbook pro running snow leopard and using terminal to ssh into remote hosts on my work network. I am noticing a strange thing when I copy and paste things in the terminal.
For example I will grep for something like this in a file:
samtools view sorted-616.bam | grep 'SOLEXA9:1:1:30:3316:10211' | head -n 1
and it gives
SOLEXA9:1:1:30:3316:10211 69 k26_179705 159 0 * = 159 0 TATGCCGCCAAACGCTTCCGCAAAGCTCTGTGTTTGACTATGTAGCGACTA CBCCCCCC#CCCCCCCCC?#CC?CC########################## RG:Z:1
But now when I select it, hit command+c to copy, and then command+v to paste, it comes out like this:
SOLEXA9:1:1:30:3316:1021169k26_1797051590*=1590TATGCCGCCAAACGCTTCCGCAAAGCTCTGTGTTTGACTATGTAGCGACTACBCCCCCC#CCCCCCCCC?#CC?CC##########################RG:Z:1
Notice how there are no spaces in between fields now. Is there a special method to copy and paste things exactly as they are?? Why is terminal behaving this way?
What happens when you use pbcopy?
samtools view sorted-616.bam | grep 'SOLEXA9:1:1:30:3316:10211' | head -n 1 | pbcopy
This should do the same thing that the copy command does, but without having to select the output you want.
Have you tried another terminal emulator? I use iTerm2 because it will copy to the clipboard on selection without having to hit Command-c.
EDIT: You may have to install Apple's developer tools to get the pbcopy/pbpaste tools.
No idea why the spaces are missing from the pasted text, but I'd try to write the output to a file, open up the file in an editor and try to see if it's something other than the standard space/newline characters. You seem to know your way with piping, but anyway:
samtools view sorted-616.bam | grep 'SOLEXA9:1:1:30:3316:10211' | head -n 1 > file.txt
It might depend on which system the host is running. I have had some issues while on ssh connections to linux/unix hosts, while Mac-to-Mac usually works just fine.