Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
using_awk_to_pull_specific_lines [2010/12/15 21:00]
Joel Dare
using_awk_to_pull_specific_lines [2023/05/22 12:51] (current)
Joel Dare
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"​.
 +
 +<box 50% round orange|Sweet Awk Magic>​[[https://​course.joeldare.com/​awk/​|Join my 90-minute workshop and learn my tips and tricks to quickly process CSV files with Awk.]]</​box>​
 +
 +===== 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