我有文件test.txt
使用正則表達式中的if語句
class c1 {
___________ any text _____________
}
class c2 {
___________ any text _____________
}
class c3 {
___________ any text _____________
}
我寫bash腳本掃描test.txt
一行一行地比較正則表達式的每一行,以獲得包含類的頭線比較字符串,但不工作:(
#!/bin/bash
while read line
do
if [[ "$line" =~ "class *\w+" ]]; then
echo $line
fi
done <test.txt
最終目標每個類文件分開
你的意思是在新文件中寫入每個類?通過分開檔案中的每個班級,你的意思是什麼? –
@JS웃這是我的意思是寫每一類中的新文件 – Steve