Get ready:
Cat Test.txt 1 3 4
Example:
Cat Xargs 1 3 4
You can see that the resulting string is separated by a space.
Separate the above string with a comma, you can use the TR command to replace the space
Cat Xargs TR ' ' ' , '
However, the TR command can only replace a single character, and multiple characters cannot be implemented.
Use SED to implement the substitution of multiple strings:
Cat Xargs sed /s//','/g
SED can replace more than one string, can compensate for the shortage of TR, the following G means matching multiple.
Summarize:
There are many substitution and merge commands, mainly to see how you solve the problem, mainly based on Xargs and TR implementation, of course, you can also use the SED command to replace, sed command support multiple strings.
Reference:
Http://man.linuxde.net/xargs (Xargs usage)
HTTP://MAN.LINUXDE.NET/TR (TR usage)
http://man.linuxde.net/sed (SED usage)
Http://bbs.chinaunix.net/thread-1631249-1-1.html
Use Xargs to convert multiple lines of text into a single line under Linux and comma-separated by tr