How to remove characters from multiple .txt files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to remove characters from multiple .txt files
# 1  
Old 01-27-2011
How to remove characters from multiple .txt files

Friends,

I want to remove charecters from multiple .txt files.

Foe example :
Quote:
a.txt
b.txt
c.txt
In this .txt files there are many "ctrl m" present in last of each line in one .txt file.

I want to remove "ctrl m" from each line from all .txt files.

Need your help regarding this.

Last edited by Yogesh Sawant; 01-30-2011 at 05:33 PM.. Reason: added quote tags
# 2  
Old 01-27-2011
Use:
Code:
tr -d '\r' < dosfile > unixfile

For the txt.files you can use a loop like:
Code:
for file in *.txt
do
  tr -d '\r' < "$file" > unixfile
  mv unixfile "$file"
done


Last edited by Franklin52; 01-27-2011 at 06:40 AM.. Reason: Adding loop
# 3  
Old 01-27-2011
You can also use dos2unix filename.
# 4  
Old 01-28-2011
Quote:
Originally Posted by Franklin52
Use:
Code:
tr -d '\r' < dosfile > unixfile

For the txt.files you can use a loop like:
Code:
for file in *.txt
do
  tr -d '\r' < "$file" > unixfile
  mv unixfile "$file"
done

Hi Thanks for ur help.

I have one more query : if any word like "Sell" is present instead of "ctrl m" then how can i remove it from all .txt files.
Please help...
# 5  
Old 01-29-2011
Code:
sed -i 's/Sell//' *.txt
perl -i -pe 's/Sell//' *.txt

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to remove first few characters from multiple file names without do loop?

Hi Fellows, I was wondering how I can remove first few characters from multiple file names without do loop in unix? e.g. water123.xyz water456.xyz to 123.xyz 456.xyz Thanks Paul Thanks. (3 Replies)
Discussion started by: Paul Moghadam
3 Replies

2. Shell Programming and Scripting

Remove duplicates from two files using n characters for comparison

Hi All, I have two files file1 123456CRTGHG 125437CRNDGF 126537CRDDGF file2 123456CRTZHC 124567CJHGHG 125987CJHGDF I need to compare the two files and any records in file 1 and 2 based on initial n characters (6 in example) need to be ignored. string separated by unprintable... (2 Replies)
Discussion started by: Bruble
2 Replies

3. UNIX for Advanced & Expert Users

How to remove degree symbol from the TXT files?

I have TXT files to process but they contain the degree symbols in them due to which the processing program fails on these files. I want a unix command that will remove the degree symbols from these files. I tried using the sed command: sed 's///g' filename but it did not work. This issue... (14 Replies)
Discussion started by: khedu
14 Replies

4. UNIX for Dummies Questions & Answers

remove characters from list of files

done some homework on this-- after i remove up to and including the ) i want to take newfile.txt and use that list to remove the files from a file in my the directory pwd i have a input.txt file cat input,txt 1)mary.jpg 12)john.jpg 100)frankkfkdf .jpg i want to remove the characters in the... (1 Reply)
Discussion started by: plener
1 Replies

5. UNIX for Dummies Questions & Answers

Files with special characters - how to remove

Hi, I have a directory that has a file which contained special characters in the filename. Can someone please advise how to remove the file, preferably with a rm -i ? Thanks in advance. Listing is as below: {oracle}> ls -1b bplog.bkup.001 bplog.bkup.002 bplog.bkup.003 bplog.bkup.004... (1 Reply)
Discussion started by: newbie_01
1 Replies

6. Shell Programming and Scripting

How to remove certain lines in multiple txt files?

Hi , I have this type of files:- BGH.28OCT2008.00000001.433155.001 BGH.28OCT2008.00000002.1552361.001 BGH.28OCT2008.00000003.1438355.001 BGH.28OCT2008.00000004.1562602.001 Inside them contains the below: 5Discounts 6P150 - Max Total Usage RM150|-221.00 P150 EPP - Talktime RM150... (5 Replies)
Discussion started by: olloong
5 Replies

7. Shell Programming and Scripting

sed to remove last 2 characters of txt file

sed 's/^..//' file1.txt > file2.txt this will remove the first two characters of each line of a text file, what sed command will remove the last two characters? This is a similar post to my other....sry if I'm being lazy.... I need a file like this (same as last post) >cat file1.txt 10081551... (1 Reply)
Discussion started by: ajp7701
1 Replies

8. UNIX for Dummies Questions & Answers

problem with grep on search string in a txt file over multiple files

I have a couple of things I got stuck on 1) I have a text file containing 25k search string that I need to search against compressed file. I have used this command but somehow it doesn't seems to use all the search terms. I have put one search string per line in the txt file (I clean up... (2 Replies)
Discussion started by: m00
2 Replies

9. Shell Programming and Scripting

need help--script to filter specific lines from multiple txt files

Hi folks, - I have 800 txt files - those files are cisco router configs router1.txt router2.txt ... router800.txt I want to accomplish the following: - I want to have a seperate file with all the filenames that I want to process - I want a script that goes trough all those... (7 Replies)
Discussion started by: I-1
7 Replies

10. Shell Programming and Scripting

remove multiple characters once

i have a variable in a bash shell script called $hostname. $hostname will always be different except it will always start with "-s " that is a - an s and a space. so echo $hostname will look like this: -s somehostname.com how can i get rid of the leading -s ? ive tried tr -d but that gets... (2 Replies)
Discussion started by: norsk hedensk
2 Replies
Login or Register to Ask a Question