开发者

tr command not working

Hello every one here I have a problem. I have a file in which there is some data like this

  • mango
  • apple
  • orange
  • grapes

When I run the com开发者_开发知识库mand

 tr '\n' ' ' < file.txt

It works fine; the output was:

 mango apple orange grapes

but I have another file which has data like this

  • 12029
  • SIDRASHAHID
  • 7(outof471)

but the above command is not working on it. Is the problem that the file has numerical data?

I have even tried sed but failed.

Can any one tell me if there is a way by which I can write this data into a single line?


Converting a comment into an answer since it seems to be accurate:

What are you seeing? Could the trouble be that the file has carriage returns in it (CRLF line endings from a Windows machine)? If so, you probably see '7(outof471)' as the output.


$ cat file.txt 
12029
SIDRASHAHID
7(outof471)

use echo $():

$ echo $(cat file.txt)
12029 SIDRASHAHID 7(outof471)

If you still would like to use sed, you can:

$ sed -e :a -e '$!N; s/\n/ /; ta' file.txt 
12029 SIDRASHAHID 7(outof471)


try this:

awk '{printf $0}' yourFile
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜