[Gllug] Stories of using filters
Tethys
tet at createservices.com
Fri Mar 18 18:06:08 UTC 2005
Nix writes:
>> od
>
>Whenever you want to see WTF is going on with some binary file :)
Yes, although I've always ended up writing my own so that a) it uses hex
not octal -- od can do this for the data, but not the offset, and b) it
gives an ascii representation at the side, in the one true (BBC micro)
format:
isengard:~% dd if=map.png bs=75 count=1 2>/dev/null | hd
00000000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 .PNG........IHDR
00000010 00 00 02 17 00 00 03 00 04 03 00 00 00 65 53 58 .............eSX
00000020 ec 00 00 00 04 67 41 4d 41 00 00 b1 8f 0b fc 61 .....gAMA......a
00000030 05 00 00 00 18 50 4c 54 45 0c 09 09 3d 37 38 69 .....PLTE...=78i
00000040 6a 72 ae ae ae c3 c2 c2 d5 d4 d4 jr.........
>> tr
>
>This one is really useful. Examples (all assuming LC_COLLATE="C"):
>
>echo "$something" | tr '[a-z]' '[A-Z]' # converts to uppercase
>
>tr -d '\015' < something # proof that `dos2unix' is a pointless command
And of course, not forgetting instant rot13:
echo "$something" | tr '[A-Ma-m][N-Zn-z]' '[N-Zn-z][A-Ma-m]'
>> fmt
Handy, but see "par", which is orders of magnitude more powerful
(and useful). In particular, the ability to retain leading quote
characters/strings is a godsend:
http://www.nicemice.net/par/
>> split
>
>Another one I've never really used.
In the past it was handy for chopping files up into 1.44MB chucks so they
would fit onto a bunch of floppies, but I don't tend to do that any more.
And of note, there's no easy way to recombine them in the MS world anyway,
which caused me no end of pain:
Me: I've split the file onto floppies, and put them in the post for you.
<time passes>
User: OK, they've arrived. How do I get at the data.
Me: Cat the files together, and unzip the result with pkzip.
User: Huh?
>You probably also want to read the chapter `Portable Shell Programming'
>in the Autoconf manual, particularly the bit on `Limitations of Shell
>Builtins'
Agreed wholeheartedly. They tend towards the excessively paranoid when
it comes to portability (which coming from me is saying something), but
if more people followed the conventions listed there, I might encounter
fewer horribly broken and Linux specific scripts. That would be a good
thing...
>not everything it says necessarily matters (e.g. I've never seen a
>shell on which ! doesn't work) but a lot of it is worth bearing in
>mind, like the `echo "x$foo" | cut -c 2- | ...' convention.
Equally, I've never seen a shell where correct quoting doesn't solve
this problem, or (in the last 15 years) a system where test didn't
have a -z option.
Tet
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list