Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
@hydrurga................I wasn't ignoring you, just forgot to respond. It is a file created in linux(EDQ).The text file already has LFs on the end of all rows but I need it to be CRLF on the end of all rows
I apologize for not looking at my previous threads to prevent repeating questions. I'll try to do better.
Yes, you've said so before. And again, after two years of asking for and about scripts, the "Don't know where or how to start" argument doesn't hold up. You obviously do, but haven't shown efforts, as you've been repeatedly asked to before.
Quote:
I did try this but it only added CRLF on the first line:
Code:
sed -i 'ls/$/\r/' <filename>
Right; because if you read your OTHER nearly-identical thread, you'd see it did exactly what you asked for there; change the first line. From there, you could have:
Looked up any of the THOUSANDS of easily-found sed examples about how to change all lines in a file
Put "how to add CRLF to all lines in a text file in linux" into Google, and seen any of those many examples/explanations
Provided example data and shown your own efforts, as you've been asked many times before
But you did not. Sorry to sound harsh, but when you've not shown any effort, and don't provide details. Read the "Question Guidelines" link in my posting signature. We are happy to HELP you, but you need to show effort.
@hydrurga................I wasn't ignoring you, just forgot to respond. It is a file created in linux(EDQ).The text file already has LFs on the end of all rows but I need it to be CRLF on the end of all rows
In that case, unix2dos would probably be the best bet (it's mature and would probably be able to cope well with edge cases that you haven't considered). If you're running one of the Ubuntu family distros, the package in the repos is called dos2unix.
@rtmistler.......it is a unix file. I think sed seems easier which is why I use it.
I don't see how sed would be easier than unix2dos since the one command just does the necessary changes with no learning required and no fuss. It's very purpose is exactly what you're asking about here.
Meanwhile I will note that from the start of the question I did feel that it was lacking in preparation and detail, hence why it was approached with the questions as to what you have tried and where you are with scripting experience. The links from TB0ne, including a highly similar, if not identical, former question definitely does cause your fellow members some pause when they see repeated questions like this, which do not seem to show effort or proper preparation of the question.
Please review the links in many of our signatures discussing how to use the LQ site properly. It definitely seems that you should be at that point already given your time with the forums as well as your post count.
It is really a long process to be able to download here,I do have sed though
That's fine if this is your choice or what you feel your best options are.
You've received a great deal of advice about how to search and replace characters using sed. Plus there is your former thread on this topic that TB0ne showed, a great deal of information about sed on the web, including the manual page for sed which is likely on your system, and finally advise offered early on about how to best specify characters for search and replace.
Thus far you've shown one example and been advised what to change with it.
This process should not be one attempt, one problem post, and then repeats, instead you should make multiple attempts, try to learn from them, in order to solve your problem.
We're not trying to be mean. Sed is very simple, search for a character or expression, replace it with a character or expression, and do so globally. The output can be re-directed to a new file so you can compare A to B and you can hex dump B to verify that it changed what you expected it to change.
This has resolved my issue..
awk 'BEGIN{RS="\1";ORS="";getline;gsub("\n","\r&");print>ARGV[1]}' DWD*
From post #11, where you posted the command from your other thread from two years ago (that I GAVE YOU):
Code:
sed -i 'ls/$/\r/' <filename>
...and if you put a small amount of effort into looking at ANY of the many thousands of sed examples, you'd have seen you just had to add a g:
Code:
sed -i 'ls/$/\r/g' <filename>
...to get ALL lines.
Quote:
Originally Posted by trickydba
It is really a long process to be able to download here,I do have sed though ...and....
I'll try to do better.
Sorry...makes no sense. Those utilities mentioned are, AGAIN, probably already installed on your system. Did you even TRY to run them? And using your package manager to install them if they were missing is a simple single command...not a 'really long process'. The fact you didn't even attempt to modify the sed command (which you KNEW worked on the first line), says you didn't 'try to do better'. And this thread: https://superuser.com/questions/1565...-n-to-n/156517
....has the first "sed -e" command you stated didn't work, and ALSO the exact awk command you said DID.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.