With the command cut in bash you can extract some part of a string (characters or bytes). Let’s stop talking and put our hands on some examples:
[email protected]:/tmp$ cut -b1-6 ajax_clock_small.gif | head -n 1 GIF89a
The command cut the first byte until the byte number six from a binary file. In this case a image file. The command pipe | on the and of the string is to extract only the first row. Yeah, the cut command goes thought all lines of the file.
If you use -c instead of -b you will got the same result. “GIF89a”
You can also use a -d option to set a delimitation character. If you are using the -d option, you can get the fields in something like a array of elements. Just using the option -f and specifying the column.
<< All Posts
How to scroll window to the left or right using jQuery
Using SCP to copy files safely