且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Linux中的文本文件中用逗号替换空格

更新时间:2023-02-23 10:28:05

tr ' ' ',' <input >output 

用逗号替换每个空格,if您需要可以通过-s标志(挤压重复)传递,将SET1(空格)中列出的重复字符的每个输入序列替换为该字符的一次出现。

Substitutes each space with a comma, if you need you can make a pass with the -s flag (squeeze repeats), that replaces each input sequence of a repeated character that is listed in SET1 (the blank space) with a single occurrence of that character.

使用替换标签后使用的挤压重复:

Use of squeeze repeats used to after substitute tabs:

tr -s '\t' <input | tr '\t' ',' >output