How to using multiple delimiters in awk and sed

When we deal with daily development processing logs, we often encounter the use of delimiters to separate fields.

Due to the inconsistent log format, sometimes there are cases where multiple delimiters are used?

So how to separate fields based on multiple delimiters?

The answer is awk command and sed command.

The log file format is as follows:

➜ cat test.log

#desired result

12 hello
01 ggrep
99 awk
15 hel

Using awk command

➜ awk -F'[:=|]' '{print $1, $2, $3}' test.log

The -F fs option defines the input field separator to be the regular expression fs.

Using sed command

➜ sed 's/[:=|]/ /g' test.log

Add a Comment

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