Learn to Code by Making Art
Learn programming while your create computer art by copying code from my free guide.
https://splashofcode.com

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

Learn to Code by Making Art
Learn programming while your create computer art by copying code from my free guide.
https://splashofcode.com
comments powered by Disqus
using_awk_to_pull_specific_lines.txt · Last modified: 2010/12/15 21:00 by Joel Dare