Sponsored Content
Top Forums Shell Programming and Scripting Removing ^M from last line alone of a UNIX File Post 302908573 by Agantrope on Tuesday 8th of July 2014 10:50:11 PM
Old 07-08-2014
Removing ^M from last line alone of a UNIX File

Hi All,

I am copying a file from windows to UNIX. After that copying it have the ctrl+M character in the file at the line break. But the file contains the data that also have ctrl+M. I want to re move the ctrl+M at the end of the line alone.

My file structure is XML and last line doesnt contains the ^M character.

eg.

Code:
aaaaaaa^M
bbbbbbb^M
ccccccc^M
ddddddd

I tried using sed for removing the ^M, after the using the command sed 's/.$//g/' the output will be like

Code:
aaaaaaa
bbbbbbb
ccccccc

(last line is removed)

When i tried using the tr command, it is functioning the same way like dos2unix.

Please suggest a solution for this.

Last edited by Don Cragun; 07-08-2014 at 11:59 PM.. Reason: Add CODE tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing Carriage Return and or line feed from a file

Hello I'm trying to write a shell script which can remove a carriage return and/or line feed from a file, so the resulting file all ends up on one line. So, I begin with a file like this text in file!<CR> line two!<CR> line three!<CR> END!<CR> And I want to end up with a file... (1 Reply)
Discussion started by: tbone231
1 Replies

2. Shell Programming and Scripting

Removing a particular line from a text file

Hi, I have a file called inp.txt the contents of the file are as follows MANI123|23|41 MANI123|96|23 I want to reove the first line of this file. How can I do it. Thanks in advance (5 Replies)
Discussion started by: sendhilmani123
5 Replies

3. Shell Programming and Scripting

Removing text from a line in a file

Hi All, I would like to know how to remove text from a line in a file. eg to The 4 sets of numbers are not static ie they change on each line in each different file so if anyone can help that would be great. Jeremy (10 Replies)
Discussion started by: outthere_3
10 Replies

4. Shell Programming and Scripting

Removing last line from file

Hi, I searched the forums but could not find anything that was very useful. I am trying to remove the very last line from a file and display the rest of the file. Is there a way to use cut and tail together? Any other suggestions? Thanks (8 Replies)
Discussion started by: akeenabawa
8 Replies

5. Shell Programming and Scripting

Removing last character from each line of file

How can I remove the last character from each line of a file? This must be done without "funny" characters, as I want to transfer the code to/from Windows. Any ideas? (17 Replies)
Discussion started by: cjhancock
17 Replies

6. Shell Programming and Scripting

Removing same line from a file

Hello , I got a text file like that with many same line main/a/antlr/ main/a/apache2/ main/a/app-install-data-ubuntu/ main/a/apparmor/ main/a/apport/ main/a/apport/ main/a/apport/ main/a/apport/ main/a/apr-util/ main/a/apr-util/ main/a/apt/ main/a/apt/ main/a/apturl/the output... (1 Reply)
Discussion started by: davidkhan
1 Replies

7. Shell Programming and Scripting

Removing the sas comment line using UNIX

I have tried a lot, Need your help guys. SAS Program: data one ; /* Data step */ Input name $; /*Dec variables*/ I want to remove the commented part(/* Data step */) alone. I have tried using sed command but it is deleting the entire line itself. i need unix command to separate this and... (6 Replies)
Discussion started by: saaisiva
6 Replies

8. Shell Programming and Scripting

Removing SAS multi line comments in UNIX

i have to remove the commented (/* . . . .*/) part which starts in one line and ends in other.help me with generic code because i have 1000 to 10k lines code which i have to remove. data one; set work.temp; input name age; infile filename; /* dfsdf dsfs sdfdf dsdd sdfsf sdfsf sfs... (4 Replies)
Discussion started by: saaisiva
4 Replies

9. Shell Programming and Scripting

Help in removing control M and Line feed in output file.

Hi All, In my output file i am getting control m character and also the line feeds at different places and with different combinations, the content of the file is supposed to be in a single line but if there is a line feed in between then from there onwards it's going into new line. I tried... (7 Replies)
Discussion started by: Bipin Kumar
7 Replies

10. Shell Programming and Scripting

Removing last character of a specific line from a file

Hello guys, I would need to remove the last character ")" of a specific line. This can be from any line. Your help is appreciated. Below is the line. HOSTNAME=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)) Please help. (6 Replies)
Discussion started by: sang8g
6 Replies
HEXCURSE(1)						      General Commands Manual						       HEXCURSE(1)

NAME
hexcurse - an ncurses-based hex editor SYNOPSIS
hexcurse [ -? | -help ] [ -a ] [ -r rnum ] [ -o outputfile ] [ [ -i ] inputfile ] DESCRIPTION
hexcurse is an ncurses-based hexeditor utility that is able to open, modify, and save a file to disk while providing useful editing and searching options. OPTIONS
-? | -help Prints out the command usage info -a Specifies the addresses to be output in decimal format initially. -r rnum Specifies the number of characters per line that the hexeditor should output. If rnum is either less than 1 or greater than the columns of the current terminal, hexcurse will fill the terminal width, just as if the -r was not specified. -o outputfile Specifies the output file to be written to by default. [-i] inputfile Specifies the input file to be read in. -i is not needed if inputfile is the last argument on the line. INTERACTIVE OPTIONS
F1 | ctrl+? Shows key command help. F2 | ctrl+s Save the current file. F3 | ctrl+o Opens a file. F4 | ctrl+g Goto a certain location in the current file. Depending on which way the addresses are being viewed at the moment, the search will behave differently. If the addresses are currently in hex format, the search will search as if the input was given in hexadecimal format. If the addresses are in decimal format, the function will search for the address in decimal. F5 | ctrl+f Search for a certain string in the current file. Depending on which window the user is currently editing in, this search will behave differently. If editing in the hex window, the input should only be in hexadecimal, and it will search for the hexadecimal "string." If the current editing window is the ASCII window, the input should be ASCII characters, and the search will find that ASCII string in the file. F6 | ctrl+a Switch between hexadecimal address values and decimal address values. F7 | TAB Switch between the hexadecimal and ASCII editing windows. F8 | ctrl+q | ctrl+x Exit out of the program. Page Up | ctrl+u Scroll one 'page' up. Page Down | ctrl+d Scroll one 'page' down. Home | ctrl+t Returns to the top of the file. End | ctrl+b Jumps to the bottom of the file. ctrl+z Undo the last modification. Can be used multiple times. Esc Escapes out of the save, open, goto, and find prompts. SEE ALSO
hexdump(1) , ncurses(3) AUTHORS
The authors of hexcurse are: jewfish <jewfish@jewfish.net> armoth <uknowho@jewfish.net> The current version of this software is always availabe at http://www.jewfish.net/software.php BUGS
On some terminals the function keys will not work. Support for resizable terminals is still a bit rudimentary. At this time, when the terminal is resized, the cursor is positioned at the beginning of the file. This will be corrected in the next release. There is also an issue where the labels on the bottom of the screen do not resize correctly. A fix for the latter is in the works. To report a bug or problem, please e-mail: devel@jewfish.net TODO
When we get the time, we would like to implement the ability to insert and delete data from the file. Please e-mail us with any additional suggestions. 22 December 2003 HEXCURSE(1)
All times are GMT -4. The time now is 03:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy