简体   繁体   中英

Sorting using Ack Grep Linux

I have this file in format:

ID:10Time:[12:55:28.156452]
ID:11Time:[12:55:28.156542]
ID:12Time:[12:55:28.157418]
ID:13Time:[12:55:28.157446]
ID:14Time:[12:55:28.167463]
ID:15Time:[12:55:28.167490]
ID:16Time:[12:55:28.176210]

I would like to sort this file based on the Time Stamp value in braces. I am a beginner in this, I think this will give me a start.

与-kn标志一起使用sort

sort -k2 file

You can sort the file with the sort utility:

sort -t'[' -k2 infile.txt > outfile.txt

You can sort the lines according to one or several keys which you specify with -k or --key . The value refers to columns numbers, starting with 1. Usually, the columns are separated by white space, but with -t you can specify a custom field separator.

sort -t':' -k3 inputfile

-t指定字段分隔符, -k3表示行将在由从第三个字段到最后一个字段的字段组成的键上排序

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM