LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-08-2017, 12:58 AM   #16
andrew.comly
Member
 
Registered: Dec 2012
Distribution: Trisquel-Mini 7.0, Lubuntu 14.04, Debian lxde 8.0
Posts: 311

Original Poster
Blog Entries: 2

Rep: Reputation: 16
Thumbs up [solved] e23's extra exercise complete!


Quote:
Originally Posted by hydrurga View Post
An explanation of sorts can be found here:
Yes, in this explanation rush's solution gives a more simplified version, which I can accept.

My successful trial:
Code:
$ Ch16-23UnixToDOS_TextConv.sh ./A.TXT 
Original UNIX text file is "./A.TXT".
Converted DOS text file is "./A.TXT.DOS".
$ od A.TXT.DOS 
000000   S   e   e  sp   t   h   e  sp   d   o   g  cr  nl   s   e   e
        53  65  65  20  74  68  65  20  64  6f  67  0d  0a  73  65  65
000010  sp   t   h   e  sp   s   o   c   k   s  cr  nl   s   e   e  sp
        20  74  68  65  20  73  6f  63  6b  73  0d  0a  73  65  65  20
000020   t   h   e  sp   b   i   r   d  cr  nl   s   e   e  sp   t   h
        74  68  65  20  62  69  72  64  0d  0a  73  65  65  20  74  68
000030   e  sp   c   o   a   l  cr  nl   s   e   e  sp   D   o   n   a
        65  20  63  6f  61  6c  0d  0a  73  65  65  20  44  6f  6e  61
000040   l   d  sp   T   r   u   m   p  cr  nl
        6c  64  20  54  72  75  6d  70  0d  0a
Now I can make a simple script to be able to convert a UNIX-formatted text file into DOS-formatted text file, mainly through the following modifications to e23's code:
Code:
NEWFILENAME=$1.dos
sed 's/$/\r/' < $1 > $NEWFILENAME
All Complete!

Learning hands on can be as messy and changing your petrol-based automobile's oil, or fixing your man-powered bicycle. But I have made certain improvements as summed up by rtmistler below.

The thicker and deeper the mud, the more beautiful the lotus blooms. May we all live like the lotus: at ease in muddy water.

Last edited by andrew.comly; 07-08-2017 at 01:08 AM. Reason: closing comments
 
Old 07-08-2017, 04:04 AM   #17
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
Have fun with your continued exploration of Bash scripting!
 
Old 07-08-2017, 06:52 AM   #18
Laserbeak
Member
 
Registered: Jan 2017
Location: Manhattan, NYC NY
Distribution: Mac OS X, iOS, Solaris
Posts: 508

Rep: Reputation: 143Reputation: 143
dos2unix:

Code:
#!/usr/bin/perl
$/ = '';
$text = <>;
$text =~  s/\r\n/\n/gs;
print $text;
Usage:
Code:
$ chmod 755 dos2unix.pl
$ ./dos2unix.pl < BatchFtpDownloadOnlyNewFiles.bat > batch.unix

Last edited by Laserbeak; 07-08-2017 at 06:55 AM.
 
  


Reply

Tags
binary, text processing, unix


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
LXer: Shell Scripting Part I: Getting started with bash scripting LXer Syndicated Linux News 0 04-29-2015 08:03 AM
[To share Bash knowledge]Notes for Advanced Bash-Scripting Version 10 (Latest) jcky Programming 4 07-31-2014 09:24 AM
LXer: Shell scripting for system administrators: advanced techniques LXer Syndicated Linux News 0 12-14-2010 05:40 PM
Advanced PSFTP scripting Singing Banzo Linux - Software 2 07-16-2007 02:57 PM
Advanced scripting help Shinobi Linux - General 2 03-25-2005 11:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:38 PM.

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