dtpwmbp:~ pwadas$ echo "Alas poor Yorik, I knew him well" | sed -e 's/^.*poor //g;s/ well.*$//g'
Yorik, I knew him
dtpwmbp:~ pwadas$ echo "Alas poor Yorik, I knew him well" | awk '{sub(/.*poor /,"");sub(/ well.*/,"");print;}'
Yorik, I knew him
ファイル入力での使用法:
dtpwmbp:~ pwadas$ echo "Alas poor Yorik, I knew him well" > infile
dtpwmbp:~ pwadas$ cat infile
Alas poor Yorik, I knew him well
dtpwmbp:~ pwadas$ cat infile | sed -e 's/^.*poor //g;s/ well.*$//g'
Yorik, I knew him
dtpwmbp:~ pwadas$ sed -e 's/^.*poor //g;s/ well.*$//g' < infile
Yorik, I knew him
dtpwmbp:~ pwadas$ cat infile | awk '{sub(/.*poor /,"");sub(/ well.*/,"");print;}'
Yorik, I knew him
dtpwmbp:~ pwadas$ awk '{sub(/.*poor /,"");sub(/ well.*/,"");print;}' < infile
Yorik, I knew him