Tábla kinyerése SQL dumpból

Sziasztok!

Egy táblát szeretnék kinyerni egy nagy SQL dumpból. Idáig jutottam, de a $2-t a második parancs valamiért nem eszi meg. Van valakinek tippje?


#!/bin/sh

# Használat
# tabla-ki dumpfajl-neve tablanev

sed -n -e '/-- Host: localhost Database:/,/-- Host: localhost Database:/p' $1 > $2.sql
sed -n -e '/-- Table structure for table `$2`/,/-- Table structure for table/p' $1 >> $2.sql

Hozzászólások

man bash
/single quote

"Enclosing characters in single quotes preserves the literal value of each character within the quotes."

Gondolj... gondolj...

A backtickeket escape-elni kell, a változó helyettesítés pedig csak " macskakörmök között megy.
Valahogy így:

sed -n -e "/-- Table structure for table \`$2\`/,/-- Table structure for table/p" $1 >> $2.sql