get rid of "^" character in a .txt file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting get rid of "^" character in a .txt file
# 1  
Old 06-25-2010
get rid of "^" character in a .txt file

I have a file that I ran the dos2unix utility on, it cleans up pretty well, but I noticed an occasional ^M leftover, (actual characters) these may or may not be strays from my original dos file. Either way, I want to get rid of the ^ and any character that may follow. ^M ^C or whatever.
How do I get rid of ^M (a-z,A-Z) out of a text file when dos2unix does not catch it? (usually at the end of a line)
maybe the sed utility?
# 2  
Old 06-25-2010
Code:
awk '{gsub("[[:cntrl:]]","");print}' in.file > out.file

# 3  
Old 06-25-2010
^M is not the same as ^ and M put together. ^M is ascii 13, a single character.
From your description I cannot tell if you have leftover ascii 13 characters or ^ + M.
It makes a difference in the answer you get. If you are certain you ran dos2unix

then:
Code:
sed 's/\^M//g' filename > tmp 
mv tmp filename

If those are ascii 13 chacters dos2unix will get rid of them - I would run it thru dos2unix
first to be sure.
# 4  
Old 06-25-2010
Quote:
Originally Posted by jim mcnamara
^M is not the same as ^ and M put together. ^M is ascii 13, a single character.
From your description I cannot tell if you have leftover ascii 13 characters or ^ + M.
It makes a difference in the answer you get. If you are certain you ran dos2unix

then:
Code:
sed 's/\^M//g' filename > tmp 
mv tmp filename

If those are ascii 13 chacters dos2unix will get rid of them - I would run it thru dos2unix
first to be sure.
From what I tested, dos2unix gets rid of only those ^M that are at the line's end. If that character is placed in the middle of the line, dos2unix leaves it there.
# 5  
Old 06-25-2010
jim mcnamara and bartus11 it looks like they are NOT ascii13 characters they appear to be the actual ^ and the letter M. So ^+M
For some reason...I have no idea why they are there though. This is AFTER (and bef0re) I ran it thru dos2unix. The original file came from an Excel export to regular txt or .csv file...I believe. I know for sure that The contents of the original excel file is all numbers so I dont know how the ^M's got in there?
# 6  
Old 06-25-2010
Quote:
Originally Posted by ajp7701
jim mcnamara and bartus11 it looks like they are NOT ascii13 characters they appear to be the actual ^ and the letter M. So ^+M
For some reason...I have no idea why they are there though. This is AFTER (and bef0re) I ran it thru dos2unix. The original file came from an Excel export to regular txt or .csv file...I believe. I know for sure that The contents of the original excel file is all numbers so I dont know how the ^M's got in there?
Well try our code. One of those one-liners will do the trick for you.
# 7  
Old 06-25-2010
yes it worked! thank you!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

[Python] replicating "sha256 -C checksum_file.txt file.txt"

Hello everyone, Since my python knowledge is limimted, I've challenged myself to learn as much as possible to help me with my carrere. I'm currently trying to convert a shell script to python, just to give myself a task. There is one section of the script that I'm having issues converting and... (2 Replies)
Discussion started by: da1
2 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

finding the strings beween 2 characters "/" & "/" in .txt file

Hi all. I have a .txt file that I need to sort it My file is like: 1- 88 chain0 MASTER (FF-TE) FFFF 1962510 /TCK T FD2TQHVTT1 /jtagc/jtag_instreg/updateinstr_reg_1 dff1 (TI,SO) 2- ... (10 Replies)
Discussion started by: Behrouzx77
10 Replies

5. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

8. UNIX for Advanced & Expert Users

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

9. UNIX for Dummies Questions & Answers

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

10. UNIX for Dummies Questions & Answers

echo "ABC" > file1.txt file2.txt file3.txt

Hi Guru's, I need to create 3 files with the contents "ABC" using single command. Iam using: echo "ABC" > file1.txt file2.txt file3.txt the above command is not working. pls help me... With Regards / Ganapati (4 Replies)
Discussion started by: ganapati
4 Replies
Login or Register to Ask a Question