Saturday 15 September 2012

awk - Print a string range, extracting all columns -


I have a situation where I need to remove a string limit from the .txt file.

There are 5 columns, and the initial value of the string is in 3 columns. Let's call it 201. Let's also call the end of string range 251. However, I want to output all the columns, not just the column 3.

Therefore: Input file -> Remove all columns -> Identify which row to print based on that row - starting with the value of its range in column 3 -> from this value to the border To the last value -> Output this limit.

Is there an easy way to do this?

Thank you in advance! Example input data:

  # col1 col2 col3 col4 col5 42293 52029 25514 750014 6383844 42293 52028 25514 750007 6383835 42293 52027 25513 749999 6383825 .. 42293 51995 25497 749748 6383513 42293 51994 25497 749740 6383504 42293 51993 25496 749732 6383494 You can just say:  
  Awk '$ 3 & gt; = 201 & amp; Amp; $ 3 & lt; = 251 'filename  

$ 3 stands for the value in the third column of the current row, and the conditions for those rows are met; Printing) is done if you want to include the header, then

  awk 'NR == 1 || Use ($ 3 & gt; = 201 & amp; $ 3 & lt; = 251) 'file name  

NR is the current record number (default Form the current line number), then it will print the first line regardless of the content.


No comments:

Post a Comment