This is my second incomplete post that I’ve started to write about two years ago, but posting incomplete version now
.
If you are going to parse a log file or do some text-processing, there are too many ways to do those simple tasks. But I think following commands are should-be-known list:
jot-seq:
jot is a tool used for sequential or random numbers or characters but can also help you do string formatting as well. seq can be used for similar purposes but I usually prefer jot which is much more powerful. Here are some example commands:
jot 3
This will output the numbers from 1 to 3 separated with newline:
1
2
3
jot 21 -1 1.00
This command prints 21 evenly spaced numbers increasing from -1 to 1:
-1.00
-0.90
-0.80
-0.70
-0.60
-0.50
-0.40
-0.30
-0.20
-0.10
-0.00
0.10
0.20
0.30
0.40
0.50
0.60
0.70
0.80
0.90
1.00
jot -s ” -b ‘-’ 50
will print 50 hyphens:
————————————————–
-s ‘word’ option denotes the seperator string by default it is newline ‘\n’.
-b ‘word’ option is used for printing the ‘word’ repetitively.
jot -b yes 0
will print the word ‘yes’ infinitely.
jot -w tmp%d 10 1
prints the following string:
tmp1
tmp2
tmp3
tmp4
tmp5
tmp6
tmp7
tmp8
tmp9
tmp10-w option is used to print word with the generated data appended to it. Octal, hexadecimal, exponential, ASCII, zero padded, and right-adjusted representations are possible by using the appropriate printf(3) conversion specification inside word, in which case the data are inserted rather than appended.
An interesting use case for jot is below:
for f in `jot - 0 50 5` ; do ping -c 1 -m 50 10.0.2.$f ; done
This will print ping the every fifth ip address from 10.0.2.0 to 10.0.2.50.
PING 10.0.2.0 (10.0.2.0) 56(84) bytes of data.
Warning: Failed to set mark 50— 10.0.2.0 ping statistics —
1 packets transmitted, 0 received, 100% packet loss, time 0msPING 10.0.2.5 (10.0.2.5) 56(84) bytes of data.
Warning: Failed to set mark 50
— 10.0.2.5 ping statistics —
1 packets transmitted, 0 received, 100% packet loss, time 0msPING 10.0.2.10 (10.0.2.10) 56(84) bytes of data.
Warning: Failed to set mark 50
— 10.0.2.10 ping statistics —
1 packets transmitted, 0 received, 100% packet loss, time 0msPING 10.0.2.15 (10.0.2.15) 56(84) bytes of data.
Warning: Failed to set mark 50
— 10.0.2.15 ping statistics —
1 packets transmitted, 0 received, 100% packet loss, time 0msPING 10.0.2.20 (10.0.2.20) 56(84) bytes of data.
Warning: Failed to set mark 50
— 10.0.2.20 ping statistics —
1 packets transmitted, 0 received, 100% packet loss, time 0msPING 10.0.2.25 (10.0.2.25) 56(84) bytes of data.
Warning: Failed to set mark 50
— 10.0.2.25 ping statistics —
1 packets transmitted, 0 received, 100% packet loss, time 0msPING 10.0.2.30 (10.0.2.30) 56(84) bytes of data.
Warning: Failed to set mark 50— 10.0.2.30 ping statistics —
1 packets transmitted, 0 received, 100% packet loss, time 0msPING 10.0.2.35 (10.0.2.35) 56(84) bytes of data.
Warning: Failed to set mark 50— 10.0.2.35 ping statistics —
1 packets transmitted, 0 received, 100% packet loss, time 0msPING 10.0.2.40 (10.0.2.40) 56(84) bytes of data.
Warning: Failed to set mark 50— 10.0.2.40 ping statistics —
1 packets transmitted, 0 received, 100% packet loss, time 0msPING 10.0.2.45 (10.0.2.45) 56(84) bytes of data.
Warning: Failed to set mark 50— 10.0.2.45 ping statistics —
1 packets transmitted, 0 received, 100% packet loss, time 0msPING 10.0.2.50 (10.0.2.50) 56(84) bytes of data.
Warning: Failed to set mark 50— 10.0.2.50 ping statistics —
1 packets transmitted, 0 received, 100% packet loss, time 0ms
od:
od – dump files in octal and other formats. You can use it to see the non-printable characters in a file as wekkç
For example you use:
cat my_file | od -c |more
Or more clearly to see non-printable characters like tabulations, CRLF, LF line terminators in colors:
od -c | grep --color '\\.'
And the output will look like as follows:
0000000 [ D e s k t o p E n t r y ] \n
0000020 V e r s i o n = 1 . 0 \n T y p e
0000040 = L i n k \n N a m e = E x a m p
0000060 l e s \n C o m m e n t = E x a m
0000120 U b u n t u \n U R L = f i l e :
0000160 m p l e - c o n t e n t / \n I c
0000200 o n = f o l d e r \n X - U b u n
0000260 t \n
The other incredibly useful linux utilities for text processing are which I’m not going to discuss here, recommend you to do some googling about them are:
- cut – paste/join
- head – tail
- awk/sed
- uniq
- tr
- grep / ack
- perl
- tac
- sort
- split






Recent Comments