[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::digital_unix

Title:DIGITAL UNIX(FORMERLY KNOWN AS DEC OSF/1)
Notice:Welcome to the Digital UNIX Conference
Moderator:SMURF::DENHAM
Created:Thu Mar 16 1995
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:10068
Total number of notes:35879

9224.0. "Stripping out those anoying carrige returns." by SWAM1::POIANI_MI () Wed Mar 19 1997 08:28

    I have a script file sent to me in dos .txt file. I need to strip out
    the control characters that are line feeds. I tried transferring the
    file with different methods, ftp, samba, mtools, and nothing works. The
    only thing I can open the file with is the CDE text editor and the
    control characters are ignored, there is no save feature with the tool
    that strips off the control sequences.
    
    I'm sure this can be done with sed/awk or another tool. If anyone has a
    handy program to do this please let me know.
    
    Thanks in advance
T.RTitleUserPersonal
Name
DateLines
9224.1UNXA::KOPYWed Mar 19 1997 08:4417
I use the following to strip <CR>

tr -d '\015'

If this is in a script called rm_cr.sh for example you could 
do the following to strip <CR> from the file dos.txt:

  rm_cr.sh < dos.txt > unix.txt

DOS files have a ^Z as the last line, this should also be removed.

BTW, I find that doing an ftp with transfer mode set to ASCII
properly strips the carriage returns and ^Z automatically.

Hope this helps.

- Walt
9224.2vi, et. al. can do this tooNETRIX::&quot;[email protected]&quot;Farrell WoodsWed Mar 19 1997 19:0812
vi will read the file and display the carriage returns as ^M's.  You
can nuke these with this one-liner:

:s/^V^M$//

You'll be left at the bottom of the file, positioned just where you
would want to zap the ^Z.  Note that the ^V^M sequence above is ctrl-V
and ctrl-M.

	-- Farrell

[Posted by WWW Notes gateway]
9224.3close to what I useVAXCPU::michaudJeff Michaud - ObjectBrokerWed Mar 19 1997 20:079
> :s/^V^M$//

	I usually add a g to the end of this and get rid of the $ at the
	end of the pattern string, ie:

:s/^V^M//g

	this gets rid of all carriage-returns even when there are multiple
	ones on a line (some things embed more than one).
9224.4Not doing the entire fileSWAM1::POIANI_MIThu Mar 20 1997 11:276
    I am trying the VI approach... thanks for all this help folks... but
    this is only stripping out ^M from the line on I'm on, it does not go
    through the entire file. What could be the cause? 4.0b unix using the
    c-shell.
    
    Mike P.
9224.5dostounixWASTED::mapMark Parenti, Unix Engineering GroupThu Mar 20 1997 11:436
If you have SoftWindows installed you can use the provided dostounix() command 
to strip the carriage returns (or the opposite unixtodos() to put them back). 

Mark Parenti
UEG

9224.6The full command:QUARRY::reevesJon Reeves, UNIX compiler groupThu Mar 20 1997 11:4416
:1,$s/^V^M//g

The "1,$" does all lines; the "g" does all occurrences in each line.

Or use the vi-clone "vim" which has "textmode" that automatically detects a
DOS-format file; ":set notextmode" will make it write the file in UNIX format.

Or use the tr command mentioned earlier; from within vi, you can invoke it

1G!Gtr -d '\015'

Explanation: 1G goes to the top of the file.  !G filters the entire file
through the following command.

Like most simple text processing problems, there are an almost infinite
number of ways to do the task in UNIX.
9224.7:%s/^V^M//gUNIFIX::HARRISJuggling has its ups and downsThu Mar 20 1997 13:495
    vi command to remove ^M from a file
    
    	:%s/^V^M//g
    
    				Bob Harris
9224.8What about col(1)...ADISSW::TENHAVEFri Mar 21 1997 07:5215
    
    How about the col(1) command.  It works great at
    fixing those ugly ^M's.
    
    Just do this...
    
    col -b < file_to_be_fixed > new_fixed_file
    
    Give it a shot right, from your unix prompt.
    
    The file names may need to be different, but
    the mv command can restore the original name.
    
    			Tim
    
9224.9this has one potential problemNETRIX::&quot;[email protected]&quot;Farrell WoodsFri Mar 21 1997 09:0328
Our version of col will make other changes to the file (from col(1)):

...
  -h  [Digital]  Compresses spaces into tabs. This is the default.
...

Moreover you can't turn this "feature" off.  The -h flag doesn't appear
to actually do anything.  (Perhaps the manual page should have added
the phrase "see figure 1".) :-)

This compression of spaces may or may NOT be desireable...



>    col -b < file_to_be_fixed > new_fixed_file
    
    
>    The file names may need to be different...

The file names WOULD need to be different.  When you redirect stdout to
a file, the shell first truncates that file to zero length if it already
exists.  So foo <input_file >input_file will wipe out input_file.



	-- Farrell

[Posted by WWW Notes gateway]
9224.10flip it!DECC::SULLIVANJeff SullivanTue Mar 25 1997 18:0914
There is a public domain flip program (source available from gatekeeper) that
does the flip from UNIX to DOS and DOS to UNIX. I've used it on every UNIX box
I've ever worked on and have never had a problem with it.

I have the source code on my UNIX machine and also on my PC at home. When
transferring files between the two (via mtools, zip or whatever), all you need
to do is flip it to your host environment (flip -u == "to unix", flip -m == "to
msdos"). Note that you don't need to use the annoying "/" as the switch
delimiter, even when on DOS.

See http://ftp.digital.com/cgi-bin/grep-index?flip
I selected "/pub/usenet/comp.sources.reviewed/volume7/flip.Z"

-Jeff
9224.11script.tidyPERFOM::HENNINGTue Apr 01 1997 08:1616
    UNIX POWER TOOLS gave me the following which is in my bin directory as
    script.tidy and invoked as 
    
    	script.tidy <mumble.in >mumble.out
    
    #!/bin/sh
    # Public domain.
    # Put CTRL-M in $m and CTRL-H in $b
    # Change \010 to \177 if you use DEL for erasing
    eval `echo m=M b=H | tr 'MH' '\015\010'`
    exec sed "s/$m\$//
    :x
    s/[^$b]$b//
    t x" $*