How can I delete all lines before a specific string from a number of files

后端 未结 4 1859
醉话见心
醉话见心 2021-02-19 01:15

I have n files, like:

file1:

1aaa
2eee

Test        XXX
Hanna
Lars 

file2:

1fff
2ffffd
3zzz

Test        XXX
Mike
Charly         


        
4条回答
  •  灰色年华
    2021-02-19 01:49

    You can do it with bash ( eg for 1 file)

    t=0
    while read -r line
    do
        [[ $line =~ Test.*XXX ]] && t="1"
        case "$t" in
         1) echo "$line";;
        esac
    done < file > tempo && mv tempo file
    

    Use a for loop as necessary to go through all the files

提交回复
热议问题