Skip to content
Advertisement

AWK – Show lines where column contains a specific string

I have a document (.txt) composed like that.

info1: info2: info3: info4

And I want to show some information by column. For example, I have some different information in “info3” shield, I want to see only the lines who are composed by “test” in “info3” column.

I think I have to use sort but I’m not sure. Any idea ?

Advertisement

Answer

You can use awk for this. Assuming your columns are de-limited by : and column 3 has entries having test, below command lists only those lines having that value.

awk -F':' '$3=="test"' input-file
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement