AWK examples

AWK examples

Linux Text Processing Bash AWK

Few examples for AWK text processor.

Example 1

Input

card 0: AudioCard_4888 [USB Audio Device]

Output

The card ID (in the example above: 0.

Query

echo "$(echo "card 0: AudioCard_4888 [USB Audio Device]" | awk -F":" '{print $1}' | awk -F" " '{print $2}')"

Example 2

Input

card 0: AudioCard_4888 [USB Audio Device]

Output

The number after the AudioCard text (in the example above: 4888.

Query

echo "$(echo "card 0: AudioCard_4888 [USB Audio Device]" | awk -F"_" '{print $2}' | awk -F" " '{print $1}')"

Previous Post Next Post