Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.5k views
in Technique[技术] by (71.8m points)

No detect new lines inside a file for contruct a csv file in bash

I am making a csv constructor but I have some problems.

I have files like this characteristics.tmp

1083108343
1083108360
1083108378
1083108386

I have to build to this format: Name, "1083108343 ,1083108360 , 1083108378,1083108386";
I tried this

cat characteristics.tmp| paste -s -d, -

I also tried tr ' ' ','

But the output is like if there is only one element. I check the file with xxd and the character 0d0a is as it should be in the end of every line? So why is not detecting the others?

,1083108386


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Cyrus bro thank you very much. I have the solution may be useful for someone

The file have 0d0a in all end lines that is like windows works. That is why when i pass to xxd this 0d0a appears and bash works only with 0a for new line so I pass the file to dos2unix as you said and results the file is only with 0a that is the new line that is the way unix works.

BEFORE

xxd file.tmp

00000000: 3130 3633 3234 3234 3432 **0d0a** 1063242442..

AFTER dos2unix

00000000: 3130 3633 3234 3234 3432 **0a** 1063242442.

And finally all the commands like xargs,tr,paste works correct.

Thanks to everyone :D


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...