How to Extract Substrings Using the cut Command in Linux Shell Scripts

cut

-b : Splits by byte. These byte positions will ignore multibyte character boundaries unless the -n flag is also specified.
-c : Splits by character.

-d: Custom delimiter; the default is the tab character.

-f: Used together with -d to specify which field to display.

-n: Cancels splitting multibyte characters. Only used with the -b flag. If the last byte of a character falls within the range indicated by the List parameter of the -b flag, that character will be written out; otherwise, it will be excluded.

-b    .eg1: Then call cut, i.e., cut the 2nd and 5th bytes in the string.

 

echo "123abc"|cut -b 2,5

Output is 2b

 

echo "rrrrrr123456789abcdefghjklmnopq" | cut -b 11-14

 

Leave a Comment

Your email address will not be published.