Hi , i am having issue to delete specific lines directly to a file
from a filtered file i get these line numbers i want to delete :
Quote:
8
10
12
14
16
20
2242
2244
2245
2249
2251
2253
2255
|
But i not only want to delete those as also the previous line of each number .
By this i mean these lines deleted :
Quote:
7
8
9
10
11
12
13
14
15
16
19
20
2241
2242
2243
2244
etc...
|
to delete my variable lines i can do a count of number of lines in variable , then do a loop with "for i until cunt of all lines"
like this :
My file content with the lines i want to delete from another file full of text :
Quote:
8
10
12
14
16
20
2242
2244
2245
2249
2251
2253
2255
|
lndel = file with the line numbers i need to delete in the outfile witch contains a lot of text
Code:
#Here it counts how many lines need to be deleted
lnempu=$(wc -l < lndel)
# start a loop from 1 to the number of lines to be deleted
for ((i=1; i<="$lnempu"; i++))
do
# here it read line number in i
lnvar=$(sed -n "${i}p" lndel)
# here sets another variable where decreases a number from the #previous var ex: if it read 55 from 1st line in lndel file then this #variable will be 54 , this way i am able to delete the line i want #and the previous one
prevl=$((lnvar-1))
# here sed cleans the previous line
sed -i -e '${prevl}d' outfile
# here sed cleans the current target line
sed -i -e '${lnvar}d' outfile
done
fi
However , sed is not deleting directly in file and i have no idea why .