For fancier and cleaner output, try the following snippet :
showendlines(){ while read i; do od --address-radix=n --width=$(wc -c <<< "$i") -c <<< "$i" | perl -pe 's/.\K\s{2,3}//g'; done < $1 | grep --color '\\.'; }
Now you can run that with :
showendlines <FILE>
Thanks to prince_jammys to "debug" my English ;)
It takes a byte from /dev/random whose source is the kernel entropy pool (better source than other solutions). Show Sample Output
If you're going to use od, here's how to suppress the labels at the beginning. Also, it doesn't output the \x, hence the sed command at the end. Remove it for space separated hex values instead Show Sample Output
Reads 4 bytes from the random device and formats them as unsigned integer between 0 and 2^32-1. Show Sample Output
Just increase the 1 at the end if you want to generate more than one. (Alternative to "| head -n N" you could use the -b flag of od: -b $[6*N] Show Sample Output
Sometimes, in a shell script, you need a random number bigger than the range of $RANDOM. This will print a random number made of four hex values extracted from /dev/urandom. Show Sample Output
the shortest command for character 'a' i know Show Sample Output
It only encodes non-Basic-ASCII chars, as they are the only ones not well readed by UTF-8 and ISO-8859-1 (latin-1). It converts all * C3 X (some latin symbols like ASCII-extended ones) and * C2 X (some punctuation symbols like inverted exclamation) ...UTF-8 double byte symbols to escaped form that every parser understands to form the URLs. I didn't encode spaces and the rest of basic punctuation, but supposedly, space and others are coded as \x20, for example, in UTF-8, latin-1 and Windows-cp1252.... so its read perfectly. Please feel free to correct, the application to which I designe that function works as expected with my assumption. Note: I specify a w=999, I didn't find a flag to put unlimited value. I just suppose very improbable surpass the de-facto 255 (* 3 byte max) = 765 bytes length of URL Show Sample Output
'od -c' works like 'hexdump -c' but is available on other operating systems that don't ship with hexdump (e.g. solaris).
Use this the next time you need to come up with a reasonably random bitstring, like for a WPA/WPA2 PSK or something. Takes a continuous stream of bytes coming from /dev/urandom, runs it through od(1), picking a random field ($0 and $1 excluded) from a random line and then prints it. Show Sample Output
Mac OS X needs some clean up. First command works in Linux, Solaris just needs the "0000000"'s removed Show Sample Output
--format=x1 makes sure that 2 byte words do not get swapped to little-endian and that the output is exactly like the bytes are stored on disk. --address-radix=x makes sure offsets are not output in default octal base but in hex. --address-radix=n can also be used to only output data without offsets
Just use "od" and it can also dump in decimal or octal. (use -t x1 and not just -x or it confuses the byte order) There is a load of other formatting options, I'm not sure if you can turn off the address at the start of the line. Show Sample Output
Search in decimal rather than hex. od dumps the character list, cut to remove offsets, sort -u gives the used characters. seq gives the comparison list, but we need this sorted alphabetically for comm, which does the filtering. I drop to perl to convert back to characters (is there a better way?) and then use od to dump them in a print-safe format. Show Sample Output
- The last sed expression ensures the unicast/multicast bit is set to zero - The greedy space replacements are for portability across UNIX seds (note there's TWO spaces and not just one, as this web shows, in s/^ */) Show Sample Output
This provides better, but not perfect, distribution, and it works for 2^32 ≤ X ≤ 2^64. (A robust distribution requires iteration/recursion and an indeterminate amount of randomness.)
This command read the values of the superblock of a hard drive. -A --> print all -x --> exadecimal -j1024 --> skip the first 1024 bytes -N1024 --> read the next 1024 bytes Show Sample Output
This is a bit of a bash hack to catch STDERR and append a log level to it. So for example, if your script has pseudo loglevels like so: echo "INFO - finding files" [ -f ${files} ] || echo "WARN - no files found" Any subcommands that write to STDERR will screw that up Adding 2> >(fb=$(dd bs=1 count=1 2>/dev/null | od -t o1 -A n); [ "$fb" ] && err=$(printf "\\${fb# }"; cat) && echo "ERROR - $err") to the command does the following: 2> Redirect STDERR >( Spawn a subshell (STDERR is then redirected to the file descriptor for this subshell) fb=$(....) get the first byte of input [ "$fb" ] test if there's a first byte && err=$(printf....) save the output to the $err variable && echo "ERROR - $err" append your pseudo loglevel and the error message Heavily borrowed from https://unix.stackexchange.com/questions/33049/check-if-pipe-is-empty-and-run-a-command-on-the-data-if-it-isnt Show Sample Output
commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for: