Shell脚本从一个文件复制到另一个文件

时间:2016-05-24 19:48:17

标签: shell

假设有一个file.txt,其中某处介于"从这里开始" 行。所以我的要求是将整行文本从此行复制到使用 shell脚本在另一个文件中使用EOF。

1 个答案:

答案 0 :(得分:3)

#!/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"

files.txt

foo foo foo
bar bar bar
Start from here
This should be
in the file
and not anything else
相关问题