简体   繁体   中英

how to grep on a substring column

I'd like to be able to grep/print the filename based on the 5th substring column. Only the .03. files in the below example.

dd.20211014.15000.123.03.11111.txt
dd.20211014.15203.143.03.11111.txt
dd.20211014.15404.123.01.11111.txt
dd.20211014.15033.126.06.11111.txt
dd.20211014.15000.123.03.11111.txt
dd.20211014.15011.323.04.11111.txt

假设线路的布局是一致的:

grep "\.03\."

Try to list the files and grep:

ls | grep ".*03.*"

Or using find :

find . -name '*03*'

As mentioned in the comments - awk should be the weapon of choice for this:

ls | awk -F. '$5=="03"'
dd.20211014.15000.123.03.11111.txt
dd.20211014.15203.143.03.11111.txt
dd.20211014.15000.123.03.11111.txt

If you prefer regex (in case you want to later on match 03 and 04 in one go, for instance:

ls | awk -F. '$5~/0[34]/'
dd.20211014.15000.123.03.11111.txt
dd.20211014.15203.143.03.11111.txt
dd.20211014.15000.123.03.11111.txt
dd.20211014.15011.323.04.11111.txt

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