[英]How to convert a .csv file into a .txt format
csv file in excel and saved it as.txt and when I count the lines using wc -l there is one line less in the.txt format 17768 vs 17769. 1. Is this normal and if so which line is lost in the conversion? excel 中的 csv 文件并将其另存为.txt,当我使用 wc -l 计算行数时,.txt 格式的 17768 与 17769 少了一行。 1. 这是正常的吗?如果是,转换中丢失了哪一行? 2. What is the easiest way to make this conversion in bash? 2. 在 bash 中进行这种转换的最简单方法是什么? Thanks!谢谢!
wc -l
count records based on row delimiter ( \n
) most probably your last record do not have row delimiter. wc -l
根据行分隔符( \n
)计数记录很可能您的最后一条记录没有行分隔符。
For example echo
commands add a new line at the end but printf
won't.例如echo
命令在末尾添加一个新行,但printf
不会。
Demo:演示:
$echo -e "1\n2" | wc -l
2
$printf "1\n2" | wc -l
1
$
$echo -e "1\n2" | od -c
0000000 1 \n 2 \n
0000004
$printf "1\n2" | od -c
0000000 1 \n 2
0000003
$
Both printf and echo are print 2 records. printf 和 echo 都是打印 2 条记录。 But as we don't have row delimiter ( \n
) at the end of string wc
is showing only 1 record但是由于我们在字符串末尾没有行分隔符( \n
),因此wc
仅显示 1 条记录
$echo -e "1\n2"
1
2
$printf "1\n2"
1
2$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.