stripping last character from end of each line


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers stripping last character from end of each line
# 1  
Old 05-11-2004
stripping last character from end of each line

Hi, sorry for being dumb but I have a file with a variable amount of records (day to day it differs) but is fixed at 80 characters wide. Unfortunately the 80th and last charachter in each line is a "^M" carriage return character which i want to get rid of. Is there a really easy command that i can use to strip this character off the end of each line (as i say the number of lines is totally variable)


any help would be greatly appreciated
Gary
# 2  
Old 05-11-2004
The command you want is called "dos2unix" although depending on your system may be called "dos2ux" or "dos2aix" etc.
# 3  
Old 11-17-2005
stripping out end of line chars

Are there no other ways to do this besides installing a program, I need something as well at the Unix end shell script wise


Quote:
Originally Posted by Ygor
The command you want is called "dos2unix" although depending on your system may be called "dos2ux" or "dos2aix" etc.
# 4  
Old 11-18-2005
You could use sed, something like:-

sed 's/^M$//' file.txt > newfile.txt (Ctrl-v, then enter for ^M character)

or if the record-length's always going to be invariable, you could use cut.
# 5  
Old 11-18-2005
Simple and effective:
Code:
strings filename > filename.new; mv filename.new filename

# 6  
Old 11-21-2005
end of line chars

thanks for that, I tried it this morning and it's just the job...many thanks to all....
# 7  
Old 11-21-2005
you may use the sed to work it out.here is an example.

echo "which is"|sed -e 's/[a-z]$//g'

this will take out the last character.

thanks.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to add a character at end of line?

Hai, I have got a small requirement in my script. and i am using bash shell. I need to add a dot (.) for some particular line in a file. Say for example, $Cat rmfile 1 This is line1 2 This is line2 3 This is line3 O/p should be : $Cat rmfile 1 This is line1 2 This is line2. #... (2 Replies)
Discussion started by: Sivajee
2 Replies

2. Shell Programming and Scripting

Adding end of line character in the last record

Need to add end of line character to last record in a fixed width file. When i take the record length of each line, for all the records it gives example like 200 except the last line as 199. Due to this my other script fails. Please help me on this. (4 Replies)
Discussion started by: Amrutha24
4 Replies

3. UNIX for Dummies Questions & Answers

Stripping double quotes from front and end of a line

I have a file and some records may contain double quotes at beginning and at end of line. So how do I strip them? For Example, file is somethings like this Field1;Field2;Field3 01;'Test';'Test Field3' "01;'This is 2nd field';This is 3rd field' " Desired Output is: ... (6 Replies)
Discussion started by: vx04
6 Replies

4. Shell Programming and Scripting

How to remove new line character at end of file.

I need to remove new line character from end of file. Suppose here are content. a|b|c|d|r a|b|c|d|r a|b|c|d|r <new line> that means file contains 4 lines but data is there in 3 lines. so I want that only 3 lines should be there in file. Please help (20 Replies)
Discussion started by: varun940
20 Replies

5. Shell Programming and Scripting

Junk Character appended at the end of a line

Hi All I have a rather unusual problem, which i have not faced till now. I have a script which exports some paths to a text file. The script runs fine but when i check the output file i can see some junk characters ^M appended at end of lines and random places. I am not able to figure... (4 Replies)
Discussion started by: raghu_shekar
4 Replies

6. Shell Programming and Scripting

append a character at end of each line of a file

Hi, i want to append a character '|' at end of each line of a file abc.txt. for example if the file abc.txt conatins: a|b|c 1|2|33 w|2|11 i want result file xyz.txt a|b|c| 1|2|33| w|2|11| I know this is simple but sumhow i am not able to reach end of line. its urgent, thanks for... (4 Replies)
Discussion started by: muaz
4 Replies

7. UNIX for Dummies Questions & Answers

How to add new line character at the end of a file

hi all, i have this question: How to add new line character at the end of a file???? i need this because i am loading a file to sybase and i have problems with the last record thanks for your help (5 Replies)
Discussion started by: DebianJ
5 Replies

8. UNIX for Advanced & Expert Users

Deleting end of line $ character in file

Hi, I've got a file where in the middle of the record is a $ end of line character, visible only when I open the file in vi and do :set list. How to I get rid of the character in the middle and keep it at the end. The middle $ character always appears after SW, so that can be used to tag it.... (3 Replies)
Discussion started by: bwrynz1
3 Replies

9. Shell Programming and Scripting

end of the line character

How do i determine what the end of the line character is in a text file. for eg. is it \n or \f or \t etc.. Is there a unix command for this? (5 Replies)
Discussion started by: zomboo
5 Replies

10. UNIX for Dummies Questions & Answers

End of line character in BAsh

I'm trying to match the end of line character in a shell script under bash. What I have done it got is a loop that reads each line of a file into a temp variable and then I get each letter of that variable and do some work on it. One think I want to do it check if the character I checking if the... (1 Reply)
Discussion started by: Rukshan
1 Replies
Login or Register to Ask a Question