would print out all lines with a 0 at the end. Since that is not happening, we have to wonder what actually follows the 0 in the lines that are not being printed. Might this be a DOS format text file that has <carriage-return><newline> character pairs at the end of most lines instead of a UNIX format text file that just has a <newline> character at the end of each line? Please show us the output from the command:
head file | od -bc
where file is the name of the sample file you showed us in post #1 in this thread.
Note that grep '0$' file will give you the lines you want to delete (not the lines you want to keep) if file really does have lines with a trailing 0 character. To get the lines you want to keep, you probably want to use:
grep -v '0$' file > new_file
after we clean up whatever is keeping the lines with a 0 at the end of a line from being recognized.
It seemed that I had \r\n at the end of the line and I replaced it with \n but the outputs are still the same.
This is what I get when I write
head file | od -bc
(the lines are actually longer so this is adapted to my sample file)
0000000 147 156 141 141 143 137 144 141 147 137 163 165 142 155 151 164
a b c _ b l a _ s u b m i t
0000020 040 055 147 167 145 145 153 040 070 060 062 040 012 147 156 141
- d e f 8 0 0 \n a b c
0000040 141 143 137 144 141 147 137 163 165 142 155 151 164 040 055 147
_ b l a etc.
That output doesn't seem to originally belong to the command you issued, and it certainly doesn't match the sample in post #1. Please apply utmost care when posting code and data!
Still from the octal dump I infer you don't have digits (incl. zeroes) at line end, but digits plus spaces. Try
Let us be clear here. The above display is not sample output from any file. The above display is not adapted output from any file. The above output is contrived output that is intended to confuse anyone who might want to help you solve your problem.
If RudiC's guess (like mine), is that the octal byte values show real data and the character values have been concocted to confuse us, then the code RudiC suggested may solve your problem. If it doesn't please show us the complete, real output from the head piped through od command I gave you so we have a chance of figuring out what is really going on.
The fake data that you did show us does not include any line that has a 0 at the end of a line (even if we ignore trailing <space>s. The only complete line shown in the seemingly real od output you concocted ends with a decimal digit 2 followed by a <space>. Guessing that all other lines in your input file (except the last one) also have trailing <space>(s) from a sample of a single concocted input line is a seemingly good guess, but it certainly isn't anything that we can rely on.
Thank you, this works now. I think I might have accidentally added the whitespace later on while I was trying to find a solution to remove 0 with text editor's options. It works now with your command and I could see how to remove whitespace too!