------------------------------------------------------------------------ gcut: extract range of characters and range of fields ------------------------------------------------------------------------ WARNING: the delimiter for gcut or cut is restricted to one characters. Be aware! $ echo "a b c" | gcut -d " " -f3 c $ echo "a b c" | gcut -d " " -f3 #returns \n Use cut with caution $ gcut -b LIST -c LIST -d DELIMITER -f LIST -s DELIMITER Infile The utility allows you to extract bytes (-b) , characters (-c) or fields defined by delimiters (-f). Other sophistications include complementing the selection criteria, ignoring certain kinds of lines, and an output field separator (OFS). [GNU cut has powerful features relative to BSD cut, whence gcut instead of cut.] -b bytes (extract bytes) -c characters (extract characters, including multi-byte chars) -d DELIMITER (only one char!) [default: tab] -f fields (extract fields) -s do not print lines not containing delimiters DELIMITER is alas restricted one character (but see "feature") LIST can be a number or range (n-m) or comma separated list (n,m-p) start number, default=1 end number, default=end of line (symbolically, $) thus -3 is equivalent to 1-3 thus 3- is equivalent to 3-$ Additional GNU options: $ gcut --output=STRING $ gcut --complement -b LIST -c LIST -d DELIMITER -f LIST --output specifies delimiter for output (cf. OFS) --complements the output (prints what is not selected) $ echo "abcde" | gcut -b 1 #-b stands for bytes a $ echo "abcde" | gcut -c 1-3 #-c stands for (multibyte) characters abc $ echo "abcde" | gcut -b 1,3,5 ace $ echo "abcde" | gcut -b 3- cde $ echo "abcde" | gcut -b -3 abc #cut by complement (everything that is not stated) $ echo "abcde" | gcut --complement -c 1-3 de $ echo "a b c d e" | cut -d " " -f 1 a $ echo "a:b:c" | cut -d":" -f1 $echo "a b c d e" | cut -d " " -f1-3 a b c #normally output delimiter is same as input #you can change that $ echo "a b c d e" | gcut -d " " --output-delimiter="," -f 1-3 a,b,c $ cat RabbitFoodRanking %This is a comment line %Comment lines do not contain delimiters %Rusty's choices Hay, 4 Lettuce, 3 Feed, 2 Sweet peas, 1 $ gcut -d, -s -f1 HelloRabbit #ignore lines which do not contain delimiter Hay Lettuce Feed Sweet peas