0

I have the following shell script that will not delete lines in the intended file. Essentially I have a document with rows of data I would like to delete. In another file I have a list of GUIDs, and if the GUID matches I want to remove it from the source file.

#!/bin/bash
while read testing
do
echo $testing
sed -i "/$testing/d" /home/bbelden/ndp.CSV
done < t2.txt

When I run this lines do not get removed from the ndp.CSV file, and if I do a ps aux while it is running I see the following command:

root      17266  107  0.0  14880  1020 pts/1    R+   17:23   0:02 sed -i /58db9697-a5d5-98ab-200e-66d0c0767147?/d /home/bbelden/ndp.CSV

Not really sure what is going on here. I am running Debian 9.

Thanks

bbelden
  • 45
  • 1
  • 5
  • For some reason it seems to be adding that trailing question mark in the sed statement as seen in the ps aux statement. Not sure why it is doing that. – bbelden Oct 25 '21 at 21:37
  • 3
    Check your `t2.txt` for carriage returns – that other guy Oct 25 '21 at 21:38
  • So strange. I've used your same script and I got everything ok. Try to see the "real" content of your files using `cat -A `, bot for ndp.CSV and t2.txt Maybe you have strange characters in some of those files (I bet for t2.txt file) – Cuauhtli Oct 25 '21 at 21:39
  • Did you consider `grep -vf t2.txt /home/bbelden/ndp.CSV`? – Walter A Oct 25 '21 at 21:49

1 Answers1

2

I had carriage returns at the end of each line since they were originally created in Windows. I was able to remove them, and now it is working as expected. Thank you!

bbelden
  • 45
  • 1
  • 5