It turns out that cmp is da bomb. cmp -l lists the locations of the bytes that are different and the two values for two binary files. So simple. Here's a link where I learned this, lots of other neat ideas there too:
http://stackoverflow.com/questions/688504/binary-diff-tool-for-very-large-files
Wednesday, November 30, 2011
Saturday, November 26, 2011
sed insert lines after a specific line
Ha, that wasn't the google search that I typed in, but better.
The approaches to this problem involve either insert or append:
http://www.thegeekstuff.com/2009/11/unix-sed-tutorial-append-insert-replace-and-count-file-lines/
or my personal favorites, "next" and "print". In the following example, the found line is deleted, and only specific lines after that are printed (I don't need to delete the found line):
http://prefetch.net/blog/index.php/2007/12/03/printing-a-set-of-lines-after-a-pattern-match/
A really impenetrable suggestion for the same thing: What is capital N?
http://codesnippets.joyent.com/posts/show/2043
So anyhow, what I am going to whip up will be to find the matching line, print the next couple of lines, then do some appends to write out the new code lines.
The approaches to this problem involve either insert or append:
http://www.thegeekstuff.com/2009/11/unix-sed-tutorial-append-insert-replace-and-count-file-lines/
or my personal favorites, "next" and "print". In the following example, the found line is deleted, and only specific lines after that are printed (I don't need to delete the found line):
http://prefetch.net/blog/index.php/2007/12/03/printing-a-set-of-lines-after-a-pattern-match/
A really impenetrable suggestion for the same thing: What is capital N?
http://codesnippets.joyent.com/posts/show/2043
So anyhow, what I am going to whip up will be to find the matching line, print the next couple of lines, then do some appends to write out the new code lines.
sed substitution case insensitive
This obviously gets googled often as it comes up as one of the autocompletes.
The answers that are returned are:
1) Use perl
2) Newer sed supports this option (i or I) but not older.
Links, which both have Use perl & update sed suggestions:
http://hintsforums.macworld.com/archive/index.php/t-19780.html
http://stackoverflow.com/questions/4412945/case-insensitive-search-replace-with-sed
The answers that are returned are:
1) Use perl
2) Newer sed supports this option (i or I) but not older.
Links, which both have Use perl & update sed suggestions:
http://hintsforums.macworld.com/archive/index.php/t-19780.html
http://stackoverflow.com/questions/4412945/case-insensitive-search-replace-with-sed
How to stop cygwin sed from changing windows CRLF to CR
This question got asked a lot on the net, largely in cygwin forums, and the answers were usually dismissive and snarky.
This is essentially the defined behavior for sed.
There are "text mount" settings in cygwin to change the default definitions of various file types. This is apparently defined when mounting a disk, and is way overkill.
There is a trick with sed where if you feed it a windows-like file, it will not do the default behavior. It's supposed to detect either a colon or a backwards slash in the file name to do this. I found the effectiveness of this to be non-straightforward.
I experimented for a while with ways to get find or grep to return a windows-like filename. There are ways.
However, it turns out that all of that was a big detour; cygwin sed has a -b option in which the file is considered "binary" and it stops mashing the CRLF and just writes the line as is.
It was about at this point that I finally began to understand the -i option, in which files are modified "in place".
This is essentially the defined behavior for sed.
There are "text mount" settings in cygwin to change the default definitions of various file types. This is apparently defined when mounting a disk, and is way overkill.
There is a trick with sed where if you feed it a windows-like file, it will not do the default behavior. It's supposed to detect either a colon or a backwards slash in the file name to do this. I found the effectiveness of this to be non-straightforward.
I experimented for a while with ways to get find or grep to return a windows-like filename. There are ways.
However, it turns out that all of that was a big detour; cygwin sed has a -b option in which the file is considered "binary" and it stops mashing the CRLF and just writes the line as is.
It was about at this point that I finally began to understand the -i option, in which files are modified "in place".
Using sed to delete lines
This question has already been blogged about plenty. Then answer is something like:
sed '/awk/d' filename.txt
It's just the d command. The blog that this came from is rich with good examples:
http://en.kioskea.net/faq/1451-sed-delete-one-or-more-lines-from-a-file
This other blog recommends using -e with sed in cases like this even when you don't think you need to, because there are many other cases where the quoted command contains "metacharacters". In any case, this blog is full of genius suggestions in general:
http://www.ceri.memphis.edu/computer/docs/unix/sed.htm
sed '/awk/d' filename.txt
It's just the d command. The blog that this came from is rich with good examples:
http://en.kioskea.net/faq/1451-sed-delete-one-or-more-lines-from-a-file
This other blog recommends using -e with sed in cases like this even when you don't think you need to, because there are many other cases where the quoted command contains "metacharacters". In any case, this blog is full of genius suggestions in general:
http://www.ceri.memphis.edu/computer/docs/unix/sed.htm
Wednesday, November 23, 2011
Hip Cat
Ah, "Hip Cat", one of T's favorite books, gotten from a book sale at our local library. Here's the book:
Having been to San Francisco, I knew where this story is set, I could almost taste the transience and art of the titular hero. The book drops all kinds of names of clubs, and to my delight I am able to learn more about them through Google.
Minnie's Can Do on Filmore is an obvious place to start. Here is a great article about Minnie, and the comments provide immense elaboration by folks who had been there:
http://newfillmore.com/fillmore-classics/minnies-can-do-club/
An overview of the history of the area and how it was all ended by the "Redevelopment Agency":
http://www.pbs.org/kqed/fillmore/learning/music/swing.html
A nice scrapbook of newspaper articles including the one above:
http://www.charliehickox.com/minnies/
This is just barely related, but just so dang interesting:
http://www.answers.com/topic/for-colored-girls-who-have-considered-suicide-when-the-rainbow-is-enuf-the-choreopoem-in-focus
SO COOL: The Hungry i and the Purple Onion still exist, apparently now under one owner?
http://www.hungryi.net/purple.htm
http://www.sfstation.com/purple-onion-b3868
The Hungry i and the Purple Onion were both part of "North Beach" area described in other articles as earlier victims of the Redevelopment Agency. They appear to have been the home of more folky to mainstream acts rather than jazz:
http://en.wikipedia.org/wiki/...From_the_Hungry_i
http://www.travisedmonson.com/smotherslenny.htm
A great article about North Beach in general -- this is where the Coit tower is?
http://www.sftravel.com/northbeach.html
Ok, Wikipedia does help here:
http://en.wikipedia.org/wiki/Hungry_i
http://en.wikipedia.org/wiki/The_Purple_Onion
Having been to San Francisco, I knew where this story is set, I could almost taste the transience and art of the titular hero. The book drops all kinds of names of clubs, and to my delight I am able to learn more about them through Google.
Minnie's Can Do on Filmore is an obvious place to start. Here is a great article about Minnie, and the comments provide immense elaboration by folks who had been there:
http://newfillmore.com/fillmore-classics/minnies-can-do-club/
An overview of the history of the area and how it was all ended by the "Redevelopment Agency":
http://www.pbs.org/kqed/fillmore/learning/music/swing.html
A nice scrapbook of newspaper articles including the one above:
http://www.charliehickox.com/minnies/
This is just barely related, but just so dang interesting:
http://www.answers.com/topic/for-colored-girls-who-have-considered-suicide-when-the-rainbow-is-enuf-the-choreopoem-in-focus
SO COOL: The Hungry i and the Purple Onion still exist, apparently now under one owner?
http://www.hungryi.net/purple.htm
http://www.sfstation.com/purple-onion-b3868
The Hungry i and the Purple Onion were both part of "North Beach" area described in other articles as earlier victims of the Redevelopment Agency. They appear to have been the home of more folky to mainstream acts rather than jazz:
http://en.wikipedia.org/wiki/...From_the_Hungry_i
http://www.travisedmonson.com/smotherslenny.htm
A great article about North Beach in general -- this is where the Coit tower is?
http://www.sftravel.com/northbeach.html
Ok, Wikipedia does help here:
http://en.wikipedia.org/wiki/Hungry_i
http://en.wikipedia.org/wiki/The_Purple_Onion
Monday, November 21, 2011
More about sed search and replace
Apparently with sed, it doesn't need the % in front of s as with vi to search and replace throughout the whole file.
Here is a very nice link with some hints, in particular:
$ find /home/bruno/old-friends -type f -exec sed -i 's/ugly/beautiful/g' {} \;
http://www.brunolinux.com/02-The_Terminal/Find_and%20Replace_with_Sed.html
Here is a very nice link with some hints, in particular:
$ find /home/bruno/old-friends -type f -exec sed -i 's/ugly/beautiful/g' {} \;
http://www.brunolinux.com/02-The_Terminal/Find_and%20Replace_with_Sed.html
Monday, November 7, 2011
IDL Create Directory:
Use the super easy FILE_MKDIR command, part of a family of os operation functions:
http://idlastro.gsfc.nasa.gov/idl_html_help/FILE_MKDIR.html
Here was the clue:
http://www.rhinocerus.net/forum/lang-idl-pvwave/139535-how-create-new-folder-idl.html
http://idlastro.gsfc.nasa.gov/idl_html_help/FILE_MKDIR.html
Here was the clue:
http://www.rhinocerus.net/forum/lang-idl-pvwave/139535-how-create-new-folder-idl.html
IDL test if directory exists
To test if a directory exists (prior to creating it) using IDL, the FILE_TEST command has a special parameter just for that:
result = FILE_TEST (,/DIRECTORY)
See here:
http://idlastro.gsfc.nasa.gov/idl_html_help/FILE_TEST.html
Look at this nightmarish way this person did it:
http://www.astro.washington.edu/docs/idl/cgi-bin/getpro/library27.html?DIR_EXIST
Another very difficult way to do this would have been to use FILE_INFO:
http://idlastro.gsfc.nasa.gov/idl_html_help/FILE_INFO.html
result = FILE_TEST (
See here:
http://idlastro.gsfc.nasa.gov/idl_html_help/FILE_TEST.html
Look at this nightmarish way this person did it:
http://www.astro.washington.edu/docs/idl/cgi-bin/getpro/library27.html?DIR_EXIST
Another very difficult way to do this would have been to use FILE_INFO:
http://idlastro.gsfc.nasa.gov/idl_html_help/FILE_INFO.html
Subscribe to:
Posts (Atom)