Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想删除 NL 字符,而不是 CR 字符后的 NL 字符。tr不会这样做。实现这一目标的最佳命令是什么?
tr
Perl 可以这样做:
$ od -c file 0000000 o n e \n t w o \r \n t h r e e \n f 0000020 o u r \r \n \n 0000026 $ perl -0777 -pe 's/(\A|[^\r])\n/$1/g' file > file.out $ od -c file.out 0000000 o n e t w o \r \n t h r e e f o u 0000020 r \r \n 0000023