Ramu Thuniki Ramu Thuniki - 3 months ago 22
Bash Question

I want to remove entire lines which contains telda(~) symbol from a given text file

File Name: case.txt

Case_1231_2369

Case_1231_2369~

Case_1231_5678

Case_1231_5678~


Required Output :

Case_1231_2369

Case_1231_5678


Give me the exact pattern or commands in unix.

Answer Source

Use grep to find all lines containing a ~. Use the -v flag to select only non-matching lines. If you want to put this into the original file, first store it in a temporary file, then rename it to the original file. (Make sure temp.txt doesn't already exist in the current directory).

grep -v "~" input.txt > temp.txt | mv temp.txt input.txt