简体   繁体   English

使用 bash 从文本文件中删除最后一个不可打印的行

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

I am visualizing occult characters from a text file with od -c .我正在使用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.我已经从应用 truncate 命令的文件中删除了最后一个换行符,但我无法删除最后一个隐匿行。 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这将检查第二个标记是否不是空字符串(因为它在最后一行)以及它是否不打印该行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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