Skip to main content
edited body
Source Link
user88036
user88036

You can try something like

#!/bin/bash 
cat file2.txt | while IFS=, read line; do

sed -i "/$(grep $line list1file1.txt)/d" file1.txt

done

Be aware that sed -i will make direct changes to file1.txt, but you can change the command to sed -i.ibk in order to save a backup copy of the original file.

For example

$cat file2.txt 
1.1.1.1
7.7.7.7

$cat file1.txt 
1.1.1.1,string1,comment1
7.7.7.7,string3,comment3
2.2.2.2,string2,comment2
88.88.88.88,string4,comment4
999.999,999,999,string5,comment5

output 
2.2.2.2,string2,comment2
88.88.88.88,string4,comment4
999.999,999,999,string5,comment5

You can try something like

#!/bin/bash 
cat file2.txt | while IFS=, read line; do

sed -i "/$(grep $line list1.txt)/d" file1.txt

done

Be aware that sed -i will make direct changes to file1.txt, but you can change the command to sed -i.ibk in order to save a backup copy of the original file.

For example

$cat file2.txt 
1.1.1.1
7.7.7.7

$cat file1.txt 
1.1.1.1,string1,comment1
7.7.7.7,string3,comment3
2.2.2.2,string2,comment2
88.88.88.88,string4,comment4
999.999,999,999,string5,comment5

output 
2.2.2.2,string2,comment2
88.88.88.88,string4,comment4
999.999,999,999,string5,comment5

You can try something like

#!/bin/bash 
cat file2.txt | while IFS=, read line; do

sed -i "/$(grep $line file1.txt)/d" file1.txt

done

Be aware that sed -i will make direct changes to file1.txt, but you can change the command to sed -i.ibk in order to save a backup copy of the original file.

For example

$cat file2.txt 
1.1.1.1
7.7.7.7

$cat file1.txt 
1.1.1.1,string1,comment1
7.7.7.7,string3,comment3
2.2.2.2,string2,comment2
88.88.88.88,string4,comment4
999.999,999,999,string5,comment5

output 
2.2.2.2,string2,comment2
88.88.88.88,string4,comment4
999.999,999,999,string5,comment5
Post Undeleted by CommunityBot
deleted 17 characters in body
Source Link
user88036
user88036

You can try something like

#!/bin/bash 
cat file2.txt | while IFS=, read line; do 

sed -i "/$(grep $line file1list1.txt | xargs sed -i '1d')/d" file1.txt

done

Be aware that sed -i '1d' file1.txt will make direct changes to file1.txt, but you can change the command to sed -i.ibk '1d' file1.txt in order to save a back upbackup copy of the original file.

For example

$cat file2.txt 
1.1.1.1
7.7.7.7

$cat file1.txt 
1.1.1.1,string1,comment1
7.7.7.7,string3,comment3
2.2.2.2,string2,comment2
88.88.88.88,string4,comment4
999.999,999,999,string5,comment5

output 
2.2.2.2,string2,comment2
88.88.88.88,string4,comment4
999.999,999,999,string5,comment5

You can try something like

#!/bin/bash
cat file2.txt | while IFS= read line; do
grep $line file1.txt | xargs sed -i '1d' file1.txt

done

Be aware that sed -i '1d' file1.txt will make direct changes to file1.txt, but you can change the command to sed -i.ibk '1d' file1.txt to save a back up copy of the original file.

You can try something like

#!/bin/bash 
cat file2.txt | while IFS=, read line; do 

sed -i "/$(grep $line list1.txt)/d" file1.txt

done

Be aware that sed -i will make direct changes to file1.txt, but you can change the command to sed -i.ibk in order to save a backup copy of the original file.

For example

$cat file2.txt 
1.1.1.1
7.7.7.7

$cat file1.txt 
1.1.1.1,string1,comment1
7.7.7.7,string3,comment3
2.2.2.2,string2,comment2
88.88.88.88,string4,comment4
999.999,999,999,string5,comment5

output 
2.2.2.2,string2,comment2
88.88.88.88,string4,comment4
999.999,999,999,string5,comment5
Post Deleted by CommunityBot
Source Link
user88036
user88036

You can try something like

#!/bin/bash
cat file2.txt | while IFS= read line; do
grep $line file1.txt | xargs sed -i '1d' file1.txt

done

Be aware that sed -i '1d' file1.txt will make direct changes to file1.txt, but you can change the command to sed -i.ibk '1d' file1.txt to save a back up copy of the original file.