- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- need to remove carriage return from end of last re...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2002 01:16 PM
тАО02-21-2002 01:16 PM
I get files with "non-printable carriage return characters" (\n in Textpad) at the end of each row. On the last row this causes an "extra row" when looked at by non-UNIX text editors. This last carriage return needs to be stripped somehow. Any ideas?
In vi I don't see anything except my normal rows. I saw that some folks see ^M, but I don't. How do I see the non printable characters in vi?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2002 01:23 PM
тАО02-21-2002 01:23 PM
Re: need to remove carriage return from end of last record in a file
:1,$s/^V^M//
The key sequence is CTRL+V and CTRL+M, only the "^M" will appear on screen.
This will remove th ^M character.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2002 01:23 PM
тАО02-21-2002 01:23 PM
Re: need to remove carriage return from end of last record in a file
There are many ways to get rid of ^M from a file here a few:
in VI
:%s/^V^M//g
^V is control V and ^M is control M or Enter
USING SED:
sed 's/^V^M//g' foo > foo.new
Also:
strings foo > foo.new
should work
-Shabu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2002 01:27 PM
тАО02-21-2002 01:27 PM
Re: need to remove carriage return from end of last record in a file
A good way to see all the characters in the file is via the od command. od -c myfile will display the stuff in a readable form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2002 02:16 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2002 09:51 PM
тАО02-21-2002 09:51 PM
Re: need to remove carriage return from end of last record in a file
Have these files been ftp'd to a Unix filesystem fro a DOS/Windows system? If so, it's likely that the ftp was done in binary mode.
While you can remove those pesky ^M characters using sed or dos2ux, I find that these CRs do not appear at all if the file is ftp'd in ascii mode.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-22-2002 06:46 AM
тАО02-22-2002 06:46 AM
Re: need to remove carriage return from end of last record in a file
I am creating the file on UNIX and then ftp'ing to a Windows server. The problem is when they try to load the file in SQL server it blows there script on that last non-printable character. It tries to load an empty row.
I did ':set list' command and I can see a $ (dollar sign) at the end of each row. There are no ^Ms or ^Vs in the file.
I did 'ux2dos myfile > newfile'. This put ^Ms in newfile. It also added a new row to the end of newfile that has '^Z$' only.
I don't want to remove the non-printable character from every row. I just want it removed from the last row. Also, I would like to be able to add the command string to my ftp script so this would not be a manual process.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-22-2002 07:33 AM
тАО02-22-2002 07:33 AM
Re: need to remove carriage return from end of last record in a file
When you ftp the file from UNIX to Windows (or vice versa), you need to use ASCII mode. This will take care of the "line delimiting" difference between UNIX and Windows.
As info, UNIX uses a newline (actually the same ascii code as a linefeed) character to delimit lines where Windows uses a linefeed and a carriage return.
If I read your post correctly, you have a blank line at the end of the file when you create it in UNIX. You need to delete that blank line before loading the file into SQL Server. Maybe you can modify how the file is created to not append the last blank line.
To better see what the last line is, use od. If the last line is blank, you would see:
tail -1 file | od -cb
0000000 \n
012
0000001
man ascii for more info on the ascii character set.
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-22-2002 07:42 AM
тАО02-22-2002 07:42 AM
Re: need to remove carriage return from end of last record in a file
tr -d \\015 < filename > newfilename
or
dos2ux filename > newfilename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-22-2002 01:59 PM
тАО02-22-2002 01:59 PM
Re: need to remove carriage return from end of last record in a file
This is an ugly little script but it should work for you. At least it did on my test file of ~500 lines. The result is all lines print as is except the last which has the newline striped off.
while read line
do
echo "$line\c"
while read line
do
echo "\n$line\c"
done
done
Darrell