【发布时间】:2016-05-24 19:48:16
【问题描述】:
假设有一个 file.txt 写在 "Start from here" 行之间的某个地方。所以我的要求是使用此行将整个文本复制到另一个文件中的 EOF shell 脚本。
【问题讨论】:
标签: shell
假设有一个 file.txt 写在 "Start from here" 行之间的某个地方。所以我的要求是使用此行将整个文本复制到另一个文件中的 EOF shell 脚本。
【问题讨论】:
标签: shell
#!/bin/bash
write_=false
while read line || [[ -n "$line" ]]; do
if [ $write_ == true ]; then
echo $line
elif [ "$line" == "Start from here" ]; then
write_=true
fi
done < "file.txt" > "other_file.txt"
文件.txt
foo foo foo
bar bar bar
Start from here
This should be
in the file
and not anything else
【讨论】:
>> other_file.txt 移出循环,移至done < file.txt >> other_file.txt,或者您为每一行打开和关闭它。