Я бы использовал Python для чего-то подобного. Вот пример:
import csv
#Create a csv file with some data
myData = [["first_name", "second_name", "Grade"],
['Alex', 'Brian', 'A'],
['Tom', 'Smith', 'B']]
myFile1 = open('file1.csv', 'w')
with myFile1:
writer = csv.writer(myFile1)
writer.writerows(myData)
#Create a second csv file
myFile2 = open('file2.csv', 'w')
#Read the first file created with data
with open('file1.csv') as File:
reader = csv.reader(File)
for row in reader:
#Print every row to the console
print(row)
if row[0] == "Alex":
#If the first cell of the row says Alex, say hi and add the row to the second file
print "Hi Alex"
with myFile2:
writer = csv.writer(myFile2)
writer.writerow(row)
Вы можете сделать это с помощью awk
следующим образом:
awk -F '**' '{print $2}' input_file
ЧТОБЫ добавить время и дату, вы можете использовать что-то вроде:
awk -F '**' '{split($1,a," ");print a[1]" " a[2]" " $2}' input_file
Это вы можете попробовать:
grep -oP "took [[:digit:]]{3,} ms" file
Выход:
took 100 ms
took 110 ms
took 400 ms
Thanks. is it possible to list down the date/time as well? something like this as output :
2020-03-11 06:19:29.857 took 100 ms
2020-03-11 06:19:29.857 took 110 ms
Предполагая, что все записи имеют одинаковый формат, проще использовать cut
, sed
и grep
:
cut -d' ' -f1,2,15-17 file | sed 's/*//g' | grep -P "took [[:digit:]]{3,} ms"
2020-03-11 06:19:29.857 took 100 ms
2020-03-11 06:19:29.857 took 110 ms
2020-03-11 06:19:29.857 took 400 ms