sh -x try.sh 2>&1 | sed "s/^+ \(.*\)$/\n$ <b>\1<\/b>/g;"
A place for John to record his techy notes, both to refer back to when needed, and as a help for others...
Monday, February 23, 2009
heads or tails? don't be so negative...
The number of lines options with
After 15 years of using head and tail (and wondering why they encourage the use of the "extra" '-n' option now!) a question just occurred to me...
"What if I don't know how many lines I want to see with tail, I just know I want to skip the first X lines...?"
The logical opposite of:
would of course be:
Which (thanks to Unix being so logical) naturally works!
You wouldn't really want to use it without a -n in front because +NUM would more likely be a valid file name than a switch, so you do get a warning:
and head just barfs:
So use:
Given the file:
Let's unit test...
means: "head the files '+2' and 'FILENAME'"
all mean: "show the first 2 lines of FILENAME"
means "show all BUT the last 2 lines of FILENAME"
means "I'm being too lazy to use -n, but show me FILENAME from line 2 down"
mean "Show me the last 2 lines of FILENAME"
means "Show me FILENAME from line 2 down"
head
and tail
do not have to be negative...After 15 years of using head and tail (and wondering why they encourage the use of the "extra" '-n' option now!) a question just occurred to me...
"What if I don't know how many lines I want to see with tail, I just know I want to skip the first X lines...?"
The logical opposite of:
tail -X FILENAME
would of course be:
tail +Y FILENAME
Which (thanks to Unix being so logical) naturally works!
You wouldn't really want to use it without a -n in front because +NUM would more likely be a valid file name than a switch, so you do get a warning:
$ tail +20 FILENAME
tail: Warning: "+number" syntax is deprecated, please use "-n +number"
and head just barfs:
$ head +20 FILENAME
head: cannot open `+20' for reading: No such file or directory
So use:
$ tail -n +$SKIP FILENAME
Given the file:
$ seq 1 5 > FILENAME
$ cat FILENAME
1
2
3
4
5
Let's unit test...
$ head +2 FILENAME
head: cannot open `+2' for reading: No such file or directory
==> FILENAME <==
1
2
3
4
5
means: "head the files '+2' and 'FILENAME'"
$ head -2 FILENAME
1
2
$ head -n 2 FILENAME
1
2
$ head -n +2 FILENAME
1
2
all mean: "show the first 2 lines of FILENAME"
$ head -n -2 FILENAME
1
2
3
means "show all BUT the last 2 lines of FILENAME"
$ tail +2 FILENAME
tail: Warning: "+number" syntax is deprecated, please use "-n +number"
2
3
4
5
means "I'm being too lazy to use -n, but show me FILENAME from line 2 down"
$ tail -2 FILENAME
4
5
$ tail -n 2 FILENAME
4
5
$ tail -n -2 FILENAME
4
5
mean "Show me the last 2 lines of FILENAME"
$ tail -n +2 FILENAME
2
3
4
5
means "Show me FILENAME from line 2 down"
Wednesday, February 18, 2009
vi - delete all matching lines...
:%g/^sometext,/ d
search range (all lines) : %
beginning with "sometext,
execute the Ex cmd "d" ; delete the line
Thought for the day...
People that call it V I instead of "vie"...
...probably don't need a "vi quick reference guide/cheatsheet" anyway.
:o)
...probably don't need a "vi quick reference guide/cheatsheet" anyway.
:o)
Tuesday, February 17, 2009
Add correct host key in /home/john/.ssh/known_hosts to get rid of this message.
john@hostname:~/.ssh$ ssh user@hostname
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: POSSIBLE DNS SPOOFING DETECTED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The RSA host key for hostname has changed,
and the key for the according IP address 123.45.67.89
is unknown. This could either mean that
DNS SPOOFING is happening or the IP address for the host
and its host key have changed at the same time.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
01:23:45:67:89:ab:cd:ef:fe:dc:ba:98:76:54:32:10.
Please contact your system administrator.
Add correct host key in /home/john/.ssh/known_hosts to get rid of this message.
Offending key in /home/john/.ssh/known_hosts:9
RSA host key for hostname has changed and you have requested strict checking.
Host key verification failed.
The known_hosts file is now encrypted, which makes it harder to find the bad line...
but you will note the line that says:
Offending key in /home/john/.ssh/known_hosts:9
(where :9 means line 9)
If you comment out or remove the line that the error indicates, this should fix the problem.
Alternatively, you can remove an entry for a given host using:
$ ssh-keygen -R hostname
Or find it with:
$ ssh-keygent -F hostname
Thursday, February 12, 2009
find grep hack to show name and content...
For a long time I've done things like:
to get both the filename and the string it's matching on because there's no "name plus match" flag for grep... you either have -l or -n but not together...
I had a brainwave just now...
If you give grep more than one file to grep in - it tells you which file it found the match in... so how about:
If you can't be bothered typing, it can be any valid filename instead of /dev/null - i.e.:
I just figured /dev/null should hopefully have the least overhead to stat.
Be careful you don't give it an invalid filename or you'll get an error for each file the find finds!
for FILE in $(find * -type f -exec grep -l "$STRING" {} \;)
do
echo -n "$FILE"
grep -n "$STRING" $FILE
done
to get both the filename and the string it's matching on because there's no "name plus match" flag for grep... you either have -l or -n but not together...
I had a brainwave just now...
If you give grep more than one file to grep in - it tells you which file it found the match in... so how about:
$ find * -type f -exec grep -n $STRING {} /dev/null \;
path/to/the/FILE:12:I found $STRING on line 12!
If you can't be bothered typing, it can be any valid filename instead of /dev/null - i.e.:
grep -n $STRING {} /
grep -n $STRING {} .
grep -n $STRING {} *
I just figured /dev/null should hopefully have the least overhead to stat.
Be careful you don't give it an invalid filename or you'll get an error for each file the find finds!
$ find * -type f -exec grep STRING {} no_such_file \;
grep: no_such_file: No such file or directory
grep: no_such_file: No such file or directory
grep: no_such_file: No such file or directory
grep: no_such_file: No such file or directory
grep: no_such_file: No such file or directory
Subscribe to:
Posts (Atom)