vendredi 6 avril 2018

Delete lines comes after a specific line in Shell

I'm trying to delete all lines comes after a specific pattern in files.

I have many files, which all have the same structure :

Example:

file1

line 1 ... line x "here there is a specific pattern" ... EOF

file2

line 1 ... line x "here there is a specific pattern" ... EOF

etc

I tried to get a simple solution, but since I have many files, I proceed with a long way :p

The pattern is appeared one time in each file.

So, I got all lines number which contains this pattern, and save in one file.

this is my code :

count=$(ls -f path_to_folder/*.txt | wc -l)
echo "Number of txt file : $count"
###


    for ((i=1;i < $count+1 ;i++))

    {

    vt=$(grep -n PATTERN $i.txt | cut -d : -f 1)
    echo $vt >> PATTERN_line.txt

    }

Aucun commentaire:

Enregistrer un commentaire