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
精彩评论