#!/bin/bash
awk -F"," '
NF == 0 {next} # skip blank line
NF == 1 {printf "%s ", } # for id line
# for data line
{
for (i = 1; i <= NF; i++) {
split($i, a, "=");
if (a[1] == "d") print $i;
}
}
' 1.log
The results are as follows:
id=1 d=4
id=2 d=20
id=3 d=5
The advantage of awk is that it can handle the input/output format in a more detailed manner.
Awk solution:
The results are as follows:
id=1 d=4
id=2 d=20
id=3 d=5
The advantage of awk is that it can handle the input/output format in a more detailed manner.
First remove the d= in id=, then
grep -o parameter Extract matching patterns. To grab the numbers again, just use awk or cut.
Or, use egrep,
There are still many methods, and other sed ones can be used;
Give me another idea...
mv 1.log /opt/www/1.log
Then use a php script to process it and create a new 1.php. The script is as follows:
This is more suitable to be done with awk or flex.
flex:
This kind of log processing can be done with awk, perl, or ruby. Last perl version
Use Python, it works well on any OS.
Use the cut command.
cut -d 'Split characters' -f 'Select the meaning of which paragraph'
There seems to be another parameter -c.
You can man it yourself.