0

I have a CSV file that I need to parse, but the first n lines of this file are worthless garbage.

Fortunately, I know the proper header line starts with foo, and that every line before the first appearance of foo at position 0 can be deleted.

tl;dr How do I make this

an unknown
number of lines
with worthless junk
that's breaking
my CSV parsing
foo,this,is,the,header,line,always,starts,with,foo
[ legit records to follow ]

Turn into this

foo,this,is,the,header,line,always,starts,with,foo
[ legit records to follow ]

I am expecting a sed-powered response to be the right course of action, but any solution that I can run from the command line is sufficient.

2
  • 4
    sed '/^foo/,$!d' ? Commented Aug 10, 2016 at 14:15
  • 1
    Or with the opposite logic sed -n '/^foo/,$p' Commented Aug 10, 2016 at 14:19

2 Answers 2

2

This will print everything after foo, inclusive:

sed -n '/foo/,$p' file

You can pipe it to another file or add the -i parameter to rewrite your file

1
  • This works, but for my purposes I'd rather not process the remainder. That's going to far bigger than the header. Commented Aug 10, 2016 at 19:14
0

Per comments and further research, here's what ultimately worked for me

sed -i '/^foo/,$!d' path/to/file

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.