Now when I execute the command,
cat test.txt | grep sun > sun.txt
text "sun" is copied to a file.
I need a help how to delete the lines which has "sun" from text.txt and save the file
Use grep's inverse option and redirect back into the file:
cat test.txt | grep -v sun > test.txt
To sum up:
cat test.txt | grep sun > sun.txt && cat test.txt | grep -v sun > test.txt