N
N
nallion2019-05-16 12:28:19
bash
nallion, 2019-05-16 12:28:19

How to parse a file?

Good day!
There is a text file with the bind log, you need to clean it from garbage
Looks like this: 16- May
-2019 12:24:46.733 192.168.60.223#49429
top-fwz1.mail.ru
12:24 192.168.60.223 top-fwz1.mail.ru
Help me write a regular expression...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
X
xibir, 2019-05-16
@nallion

perl -ne '/([^ ]+) (\d+:\d+)[^ ]+ (\d+\.\d+\.\d+\.\d+)[^ ]+ (.+)/; print "$1 $2 $3 $4\n"' test.txt

S
Saboteur, 2019-05-16
@saboteur_kiev

awk -F "[:# ]" '{print $1" "$2":"$3" "$5" "$7}' file.log

D
Drill, 2019-05-16
@Drill

SED:

re='(.*):[0-9.]+[0-9]+(.*)#[0-9]+(.*)'
while read LINE; do
    while ; do
        LINE=${BASH_REMATCH[1]}${BASH_REMATCH[2]}${BASH_REMATCH[3]}
        echo $LINE >>  /path/to/new_file
    done
done < /path/to/old_file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question