简体   繁体   中英

Removing last non-printable line from a text file with bash

I am visualizing occult characters from a text file with od -c . Here I show you the tail of this output:

0014120   .   f   a   s   t   q   .   g   z  \t   N   o   n   e  \n   N
0014140   s   a   m   p  \t   S   s   a   m   p   l   e   3   3   4   _
0014160   1   1   1   0   1   9  \t   s   a   m   p   I   _   S   1   3
0014200   _   L   0   0   1   _   R   1   _   0   0   1   .   f   a   s
0014220   t   q   .   g   z  \t   N   O   n   e   m   _   S   1   3   _
0014240   L   0   0   1   _   R   2   _   0   0   1   .   f   a   s   t
0014260   q   .   g   z  \t   N   o   n   e   \n
0014271

I have removed the last newline character from the file applying truncate command, but I am not able to remove the last occult line. I would like to get this:

0014120   .   f   a   s   t   q   .   g   z  \t   N   o   n   e  \n   N
0014140   s   a   m   p  \t   S   s   a   m   p   l   e   3   3   4   _
0014160   1   1   1   0   1   9  \t   s   a   m   p   I   _   S   1   3
0014200   _   L   0   0   1   _   R   1   _   0   0   1   .   f   a   s
0014220   t   q   .   g   z  \t   N   O   n   e   m   _   S   1   3   _
0014240   L   0   0   1   _   R   2   _   0   0   1   .   f   a   s   t
0014260   q   .   g   z  \t   N   o   n   e

Do you know what do I need to get it?

Thanks in advance

You can try something like:

awk '{if ($2!="") print}' input_file

this will check if second token is not empty string (as it is on the last line) and if it is not print the line

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM