Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Last revision Both sides next revision
using_awk_to_pull_specific_lines [2010/12/15 21:00]
Joel Dare
using_awk_to_pull_specific_lines [2020/06/01 22:53]
127.0.0.1 external edit
Line 1: Line 1:
 +====== Using AWK and SED on CSV or TEXT Files ======
  
 +===== Using AWK to Pull Matching Lines =====
 +
 +You can use AWK to pull a specific set of lines from any text, CSV, html, or XML file.  Use AWK as a substitute for CAT when you need to pull text from one specific line to another specific line.
 +
 +Here's the simple AWK command that you can use.
 +
 +  awk '/My Start String/,/My End String/'​ file.txt
 +
 +That simple command will output the data in file.txt starting with the text "My Start String"​ and ending with the text "My End String"​.
 +
 +===== Using SED to Pull Specific Line Numbers =====
 +
 +You can use SED to pull a specific range of lines, by line number, from any text file.  Here's the simple command.
 +
 +  sed -n <​start>,<​end>​p <​file>​
 +
 +And here is an example.
 +
 +  sed -n 1131,1152p sample.txt
 +  ​
 +That command pulls lines from 1131 to line 1152 from the sample.txt file.
 +
 +====== See Also ======
 +
 +[[Using AWK on CSV Files]]
comments powered by Disqus
using_awk_to_pull_specific_lines.txt · Last modified: 2023/05/22 12:51 by Joel Dare