AWK tutorial: split on character awk or cut

In the previous article, we introduced the use of linux awk for string cutting. Here we introduce a method.

use awk -F parameter

➜  awk echo "a:B:C:CS:DDDD" | awk -F":" '{print $2}'
B

use awk split function

➜  awk echo "a:B:C:CS:DDDD" | awk '{split($0, a, ":");print a[2]}'
B

For more awk usage, please refer to the following article:

Let’s look at another approach — linux cut command

linux cut — cut out selected portions of each line of a file.

use cud -d parameter

-d delim
Use delim as the field delimiter character instead of the tab character.

➜ echo "a:B:C:CS:DDDD" | cut -d ":" -f2
B

More about cut:

➜ man cut


More about Linux commands: Linux Commands Tutorial

Add a Comment

Your email address will not be published. Required fields are marked *