First, you can set multiple separators for split.
Example 1.
Output the following text and extract the two numbers at the end of each line. For example, extract from the first line and 8 from the second line.
ERROR20121211 11:35:00[AppWorker] __LSE vec_txt_size:185 vec_pic_size:5 ERROR20121211 11:35:00[AppWorker] __LSE vec_txt_size:8 vec_pic_size:1ERROR20121211 11:35:00[AppWorker] __LSE vec_txt_size:46 vec_pic_size:20 ERROR20121211 11:35:00[AppWorker] __LSE vec_txt_size:0 vec_pic_size:0
The delimiter can be set to a colon or space.
awk -F"\t" '{split($0,array,/[: ]/);for(i=1;i<=length(array);i++)print array[i]}' $INPUTFILE
Example 2.
Arglst = "5p12p89"
Delimiter set to P or P
split( ArgLst, Arr, /[Pp]/)
After execution: arr [1] = 5, arr [2] = 12, arr [3] = 89
Second,-F can also set multiple delimiters. In general, awk-F' \ T' is often used to represent the delimiters, such
awk -F '\t' '{print $1}' file1.txt
The processing program file1.txt is separated by a tab (\ t), and the first column is printed.
Now let's assume that you want to process a piece of text. Each line has multiple separators. For example, we need to extract the number 244 after the PIC in the following line of text and the number 246 After the TXT,
20130304 16:50:00 [Normal predict] word: mobile phone pic: 244 TXT: 246
If you can specify a separator that can be either a space or a colon, the processing will become simple. You can use a regular expression to specify multiple separators in the format of-F' [space:] + 'as follows
awk -F'[ :]+' '{print $NF"\t"$(NF-2)}' file1.txt
The output result is
244 246
Example 3: Similarly, if you want to specify (and, as the separator, you can write
awk -F '[(,]' '{print $2"\t"$3}'