我有以下格式的文件:
B: that
I: White
I: House
B: the
I: emergency
I: rooms
B: trauma
I: centers
我需要做的是从顶部逐行读取,如果该行以B开头然后删除B:如果它以I开头:然后删除I:并连接到前一个(前一个处理相同规则)。
预期输出:
that White House
the emergency rooms
trauma centers
我尝试了什么:
while read line
do
string=$line
echo $string | grep "B:" 1>/dev/null
if [ `echo $?` -eq 0 ] //if start with " B: "
then
$newstring= echo ${var:4} //cut first 4 characters which including B: and space
echo $string | grep "I:" 1>/dev/null
if [ `echo $?` -eq 0 ] //if start with " I: "
then
$newstring= echo ${var:4} //cut first 4 characters which including I: and space
done < file.txt
我不知道的是如何将它放回线路(在文件中)以及如何将线路连接到之前处理的线路。