Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[OT] add carriage return to text files

55 views
Skip to first unread message

dale

unread,
Feb 19, 2017, 5:41:51 PM2/19/17
to
I have a bunch of octave, gnuplot and awk files that I made in gedit on
linux, they only have a linefeed at the end of a line, I would like to
add a carriage return after each linefeed so I can see them on windows

any ideas? probably could do an awk file on each, that would save some time

want to do them in a batch all at once, guess I could do a bash script
of awk conversions

if someone has already done this, or knows how, would you point me in
the right direction?

tried to google some ...


--
dale | http://www.dalekelly.org

Janis Papanagnou

unread,
Feb 19, 2017, 6:18:02 PM2/19/17
to
On 19.02.2017 23:41, dale wrote:
> I have a bunch of octave, gnuplot and awk files that I made in gedit on linux,
> they only have a linefeed at the end of a line, I would like to add a carriage
> return after each linefeed so I can see them on windows

The order is CR LF (not LF CR).

>
> any ideas? probably could do an awk file on each, that would save some time
>
> want to do them in a batch all at once, guess I could do a bash script of awk
> conversions
>
> if someone has already done this, or knows how, would you point me in the
> right direction?

Various possibilities exist. Since you mentioned awk you can use this awk code
(which only changes the output record separator) to embed in your bash script

awk -v ORS="\r\n" '1'

If you use some recent GNU awk there's an inplace editing option available

awk -i inplace -v ORS='\r\n' '1' files...

so you don't need any additional bash commands around that call.

Janis

dale

unread,
Feb 19, 2017, 6:38:16 PM2/19/17
to
Thanks Much!!!
be back after I give it a try this evening

--
dale | http://www.dalekelly.org

Kaz Kylheku

unread,
Feb 19, 2017, 6:54:09 PM2/19/17
to
On 2017-02-19, dale <da...@dalekelly.org> wrote:
> I have a bunch of octave, gnuplot and awk files that I made in gedit on
> linux, they only have a linefeed at the end of a line, I would like to
> add a carriage return after each linefeed so I can see them on windows

Learn real editor.

Vim:

:set fileformat=dos
:w

File now saved with CR-LF line endings. Next time you open the file,
Vim will automatically use this fileformat setting.

If you you are just simply using a shared folder between Linux and
Windows, or copying the files back and forth, consider just keeping the
files in Windows format. If Octave and Gnuplot on Linux don't mind
the CR's, you're just fine. Edit in a decent editor and you won't
see the line endings.

Regarding conversion, the manpage for "unix2dos" and "dos2unix".

Another thing: you should consider putting your files into a
cross-platform version control system like Git. A version control system
can create a working copy of text files in the local operating system
format.

You can make a change on Windows to your Octave or Awk code,
commit the change, then push it out to your Linux-side repository
where the update is seen in Unix format.

No software developer worth their salt performs conversions on
their maintained source code between Unix and Windows. Version
control takes care of it.

I wouldn't develop anything other than throwaway code without version
control.

dale

unread,
Feb 19, 2017, 7:15:36 PM2/19/17
to
Thanks Much!!!
be back when I give it a try

--
dale | http://www.dalekelly.org

Karl Ratzsch

unread,
Feb 20, 2017, 3:03:42 AM2/20/17
to
Am 19.02.2017 um 23:41 schrieb dale:
> I have a bunch of octave, gnuplot and awk files that I made in gedit on
> linux, they only have a linefeed at the end of a line, I would like to
> add a carriage return after each linefeed so I can see them on windows
>
> any ideas? probably could do an awk file on each, that would save some time
>
> want to do them in a batch all at once, guess I could do a bash script
> of awk conversions



Just don't use the horrible built-in "notepad.exe" editor on windows,
but one of the much better configurable alternatives.

Kenny McCormack

unread,
Feb 20, 2017, 3:29:13 AM2/20/17
to
This is good advice. For the most part, there's no real problem with just
leaving the files as they are (i.e., in Unix/Linux format). Most Windows
programs will work OK. It is just that the default editor - the one people
intuitively recommend for newbies, even though they'd never actually use it
themselves - is brain dead about this.

The simplest alternative is "Wordpad", which is installed by default in
Windows (no special install or configuration needed) and has no problem
displaying files w/o CRs.

But, yeah, I get caught by this every once in a while - bringing up a Unix
file in Notepad and going Arrrrghhhh!

--

First of all, I do not appreciate your playing stupid here at all.

- Thomas 'PointedEars' Lahn -

Marc de Bourget

unread,
Feb 20, 2017, 6:37:42 AM2/20/17
to
I use the great free Editor https://notepad-plus-plus.org/ on Windows with:
Settings - Style Configurator... Language: C, Default ext.: C + User ext.: awk

Then, you even have function lists for AWK within the Editor.

dale

unread,
Feb 20, 2017, 12:02:53 PM2/20/17
to
for some reason they need the carriage returns in a <div> code block in
HTML on Edge or Internet Explorer, I don't currently have an example to
show, but will be back, might be a CSS configuration for <div>

--
dale | http://www.dalekelly.org

Moai

unread,
Feb 20, 2017, 1:00:48 PM2/20/17
to
On 2017-02-19 18:54, Kaz Kylheku wrote:
> On 2017-02-19, dale <da...@dalekelly.org> wrote:
>> I have a bunch of octave, gnuplot and awk files that I made in gedit on
>> linux, they only have a linefeed at the end of a line, I would like to
>> add a carriage return after each linefeed so I can see them on windows
>
> Learn real editor.
>
> Vim:
Not everyone is using Vim, some people use nvi.

Kenny McCormack

unread,
Feb 20, 2017, 1:26:50 PM2/20/17
to
In article <o8faou$19t$2...@nearlythere.eternal-september.org>,
Be that as it may, I've just found a cute way to solve this problem, using vim.

Put all the files you want to convert into a newly created directory, and do:

$ vim -c 'bufdo se ff=dos|w' -c q *

P.S. In response to the OP, who noted, in response to my suggestion that he
just leave the files alone and not worry about it, that whatever apps he
was using were unhappy with the CR-less files:

True. Some apps do get unhappy with Unix-formatted files. Those apps
are basically brain-dead, but what can you do? You must convert your
files in order to use those apps. Such is life.

--
It's possible that leasing office space to a Starbucks is a greater liability
in today's GOP than is hitting your mother on the head with a hammer.

Marc de Bourget

unread,
Feb 20, 2017, 3:06:45 PM2/20/17
to
If you are still looking for a MS command line tool to do inplace conversion,
I have made very good experiences with this one:
http://www.efgh.com/software/unix2dos.htm

dale

unread,
Mar 4, 2017, 12:01:10 PM3/4/17
to
signed up for github, when I download a text file it still doesn't work
in notepad, but it works in wordpad

guess it is a notepad problem

--
dale | http://www.dalekelly.org
0 new messages