LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 09-19-2018, 12:31 PM   #16
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled

@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
 
Old 09-19-2018, 12:33 PM   #17
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
@rtmistler.......it is a unix file. I think sed seems easier which is why I use it.
 
Old 09-19-2018, 12:35 PM   #18
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by trickydba View Post
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.
 
3 members found this post helpful.
Old 09-19-2018, 12:46 PM   #19
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Quote:
Originally Posted by trickydba View Post
@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.
 
3 members found this post helpful.
Old 09-19-2018, 12:50 PM   #20
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by trickydba View Post
@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.
 
3 members found this post helpful.
Old 09-19-2018, 01:10 PM   #21
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
"dos2unix" is called "todos" in some distros, IIRC.
 
1 members found this post helpful.
Old 09-19-2018, 02:44 PM   #22
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
It is really a long process to be able to download here,I do have sed though
 
Old 09-19-2018, 02:58 PM   #23
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by trickydba View Post
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.
 
1 members found this post helpful.
Old 09-19-2018, 02:59 PM   #24
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
This has resolved my issue..

awk 'BEGIN{RS="\1";ORS="";getline;gsub("\n","\r&");print>ARGV[1]}' DWD*

I appreciate everyone's help!
 
Old 09-19-2018, 03:03 PM   #25
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
See the Perl and sed code (and alternatives) on this page:

https://en.wikipedia.org/wiki/Dos2unix
 
1 members found this post helpful.
Old 09-20-2018, 06:43 AM   #26
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by trickydba View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script for adding users is running but not adding users Gren Programming 2 04-27-2012 03:53 AM
Adding HD Flab0y352 Linux - General 3 08-13-2007 02:25 AM
Adding more SWAP after adding memory marc1978 Linux - General 6 03-19-2006 07:13 PM
Adding a new HD hywaydave Linux - Newbie 4 05-02-2005 03:22 PM
Adding 2.4.20 to 9.1 datamile Slackware 3 06-08-2004 10:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration