I need to copy all lines in a file matching a pattern to a second file.
In detail: I have a sql dump and want to create a second sql file which includes all commands for tables whose name matches dx_postings, dx_postings_archive, and so on. The pattern should be dx_postings.
Any ideas? I'd prefer an awk or sed solution.
The sed
solution:
sed -ne '/pattern/ p' infile >outfile
Ok, see this :
awk '/pattern/' FILE > NEWFILE
more specific :
awk '/^(DROP|LOCK) .*dx_postings/' file.sql > newfile.sql
If you have INSERT or CREATE statements, this is more tricky because there's more than one lines.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With