Reputation
858
Top tag
Next privilege 1,000 Rep.
See votes, expandable usercard
Badges
1 6 27
Impact
~51k people reached

Mar
21
awarded  Famous Question
Feb
8
revised Combining strings command and grep: how to limit results to null-terminated strings
edited tags
Feb
8
comment Combining strings command and grep: how to limit results to null-terminated strings
As usual, you're simply a magician. :-O Thank you so much. Had not the slightest idea that tr would even understand a whole set like [[:print:]]instead of mere dumb single characters (i. e. the purpose it would normally serve). Might take me a while to have your partially "golfed" solution broken down to things I can follow, but nevermind: I think I can master that on my own. Thanks again.
Feb
8
comment How to get a string between two special characters using Shell?
@StéphaneChazelas I was just as confused as you were...Well, for a starter: when I want a string between two special characters I usually assume that there will be no special character of the same kind in between! So to say, parsing the (silly) string &%asdf$Chris$fdsa?# for "the string between the $" would clearly mean that the result is Chris and, as visible, there is no other $ sign in between. How else could the parser decide?? -- This question ought to be flagged as "too specific" as the technique described in the answers may not be needed elsewhere but in this lone case.
Feb
8
revised Combining strings command and grep: how to limit results to null-terminated strings
Wording in add.note amended. (Man, grammar in this one is tricky.)
Feb
7
comment Combining strings command and grep: how to limit results to null-terminated strings
@MarkPlotnick Well, actually I thought that if someone posts a solution for '\x00', I can also make this work for, say, '\x07'. Plus, iit was in fact a matter of physical length of question title: now picture something like "Combining strings command and grep: how to limit results to strings terminated by NUL or similar non-printable characters" :-) Ugh. TL;DR. So I chose the most significant case and I am going to adapt similar cases accordingly.
Feb
7
revised Combining strings command and grep: how to limit results to null-terminated strings
added 2 characters in body
Feb
7
comment Combining strings command and grep: how to limit results to null-terminated strings
@MarkPlotnick Well I always love to be as portable as possible. :) Thanks for the heads-up with -o, as I didn't consider it absolutely necessary. However, if it can eliminate said artifacts, I might include it in the grep options. Besides: I chose the NUL as most common case, but it might indeed be a \x01 in another. So there'd be your control code, all of a sudden! :) That reads, the ideal way would be to find a solution that will work a) without -a and b) for ALL [^[:print:]]
Feb
7
comment Combining strings command and grep: how to limit results to null-terminated strings
@MarkPlotnick Indeed it would, however there appears to be a general problem with \xAA hex codes in the grep regex. Spotted lots of similar questions here on SE. Users occasionally had to work around it by greping for 'XYZ'$'\x00', i. e. using the built-in trickery of some (not all!) shells. Maybe hex codes in grep will only work reliably in GNU grep? Besides: -a is discouraged, as it might wreak havoc on a terminal due to the shell interpreting some of the control codes as actual ones. So these might clear your screen, deface output strings, insult your mother...;-)
Feb
7
comment Combining strings command and grep: how to limit results to null-terminated strings
Sounds like a good idea, but I should see some sample line first instead of blind fiddling. Plus, it would be great to keep using strings, because with big files it will already have filtered so much garbage before grep even gets its first attempt to process the content.
Feb
7
revised Combining strings command and grep: how to limit results to null-terminated strings
Oops! Wrong field. Sorry but the server is under heavy load and seems to be taking up to 30 secs to finish loading the page.
Feb
7
revised Combining strings command and grep: how to limit results to null-terminated strings
-d removed from trings options. Although I do need it that way, it might become a little too specific.
Feb
7
asked Combining strings command and grep: how to limit results to null-terminated strings
Feb
1
comment How can I get my external IP address in bash?
Got it working with some decent lot of regex magic, but it wasn't easy. Should you insist on using this service, be sure to wrap that line into a script: $ curl -s http://whatismyip.org | grep -o '\([[:digit:]]\{1,3\}\.\)\{3\}[[:digit:]]\{1,3\}'
Feb
1
comment How can I get my external IP address in bash?
+1 Albeit looking so clumsy, this approach has been a life-saver for me too a few times. Because Internet is not WWW. You can have internet access, but you may (commonly in server rooms) be doomed to a non-GUI console, and in this case it's important to remember by heart one of the checkIP service URLs. And as this one is pretty common, it's only seemingly compilcated, as you will be more likely to remember the DynDNS one than the one of amazonaws. That is, if you have NO way to google for it. (not even lynx).
Jan
31
comment Redirecting stdout to a file you don't have write permission on
Well I would be pretty satisfied with 4 :-D Your English is not bad at all. It's just worded in a kind of terse techie nerdspeak. I must guess you're a coder. Coders amongst each other will understand themselves perfectly that way, but a non-coder must think it's worded like...as said.
Jan
29
comment SmartMonTools: How can I know if there is any smartctl test running on my hard disk?
@frostschutz "smartctl -H is a false friend in that regard." You can say that again! I too have fallen for this option once, thinking it might have to do with the self-tests...but no, entirely different subject (and purpose).
Jan
29
comment Redirecting stdout to a file you don't have write permission on
@umeboshi But reliable only if you're experienced enough to know exactly what you're doing. Fordd can be fairly dangerous (if not to say: devastating) if only a slight mistake was made. So for new users, I'd rather recommend the tee method to be on the safe shore.
Jan
29
comment Redirecting stdout to a file you don't have write permission on
This is worded like an Ancient Chinese riddle. Can't see to understand how this got so many upvotes. (hrmph)
Jan
29
comment Emptying a file for root user does not work
Thanks so much! I had one single mistake in my line, and I think I should quote it here so that people are alerted: sudo cp /dev/null > /to/be/truncated/file. I dunno why exactly it spits me out a bash: /to/be/truncated/file: Permission denied but it does. Omit that damn > and it works. D'oh. (Well, in my case, the origins may still date back to my MS-DOS times, where I would frequently use C> type (...) plus the redirection operator >.)