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
12:hello:10.23.44.100
01|ggrep|11.23.44.100
99:awk|14.33.99.124
15:hel=10.23.44.100
...

#desired result

12 hello 10.23.44.100
01 ggrep 11.23.44.100
99 awk 14.33.99.124
15 hel 10.23.44.100
...

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 *