1

Is there a way to chain commands like grep and head together to extract a portion of a file?

The problem is that somewhere in my .sql file I have an old data that I need to compare to new data and I don't know what line I need to tell Head to start at. But I only need to go for maybe 10 lines...its a small table.

I am looking for something that does

Find `database`.`tablename` | head next 20 lines to new file.txt

1 Answer 1

4

You can use -A to specify how many lines after a match you want printed.

grep -A 20 '`database`.`tablename`' dump.sql

This will of course also include the match, and you can pipe that to a viewer. There's no need for head here.

1
  • Thanks, this gave me a few more results than I needed but head cleaned it up. Thank you very much, 10000 times better than waiting to download, open, scroll, copy, paste!
    – Carter
    Jun 26, 2014 at 17:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .