Removing uppercase words from textfiles


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing uppercase words from textfiles
# 1  
Old 10-17-2006
Removing uppercase words from textfiles

I have the task of removing all uppercase words from csv files, mit
10000's lines. I think it shoud be possible with regex's, something
like "s/[A-Z]{2,}//g" but I can't get it work with sed or Vi. It would
also be possible to script in ksh, awk, perl or python.

example
this "this is a EXAMPLE text"

should become
"this is a text"
# 2  
Old 10-17-2006
this will help you:
Code:
perl -pi -e 's/[A-Z]{2,}//g;' <  samplefile > newfile

# 3  
Old 10-17-2006
In Python
Code:
#!/usr/bin/python
import re,fileinput
for lines in fileinput.FileInput("csv.txt", inplace=1):
     lines = lines.strip()
     lines = re.sub("[A-Z]{2,}",'',s).replace("  ", " ")
     print lines

# 4  
Old 10-17-2006
Thankyou: Removing uppercase words from textfiles

Thankyou both for your fast replies.

Yogesh Sawant:
worked like a dream.

ghostdog74:
became --> NameError: name 's' is not defined.
changed it to

lines = re.sub("[A-Z]{2,}",'',lines).replace(" ", " ")
and it also worked like a dream

thankyou again

best regards
frieling
# 5  
Old 10-17-2006
Quote:
Originally Posted by frieling
I have the task of removing all uppercase words from csv files, mit
10000's lines. I think it shoud be possible with regex's, something
like "s/[A-Z]{2,}//g" but I can't get it work with sed or Vi. It would
also be possible to script in ksh, awk, perl or python.

example
this "this is a EXAMPLE text"

should become
"this is a text"
Try to escape some charachters, e.g.

# sed -e "s/[A-Z]\{2,\}//g"
# 6  
Old 10-17-2006
Try also

tr -d '[:upper:]' < input_file
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add words in beginning , end after removing a word in a file

My file has the entries like below... /dev/sds /dev/sdak /dev/sdbc /dev/sdbu I want to make the file like below echo 1 > /sys/block/sds/device/rescan echo 1 > /sys/block/sdak/device/rescan echo 1 > /sys/block/sdbc/device/rescan echo 1 > /sys/block/sdbu/device/rescan (2 Replies)
Discussion started by: saravanapandi
2 Replies

2. Shell Programming and Scripting

Gawk gensub, match capital words and lowercase words

Hi I have strings like these : Vengeance mitt Men Vengeance gloves Women Quatro Windstopper Etip gloves Quatro Windstopper Etip gloves Girls Thermobite hooded jacket Thermobite Triclimate snow jacket Boys Thermobite Triclimate snow jacket and I would like to get the lower case words at... (2 Replies)
Discussion started by: louisJ
2 Replies

3. Shell Programming and Scripting

Get group of consecutive uppercase words using gawk

Hi I'd like to extract, from a text file, the strings starting with "The Thing" and only composed of words with a capital first letter and apostrophes, like for example: "The Thing I Only" from "those are the The Thing I Only go for whatever." or "The Thing That Are Like Men's Eyewear" ... (7 Replies)
Discussion started by: louisJ
7 Replies

4. Shell Programming and Scripting

removing the words with symbols in a file in unix

I have file like below Hi iam author <br>joseph</br> in france. I live in my home <br></br> but no food. I will play footbal <br></br> but i wont play cricket. I will read all the books <br>all fiction stories</br> i hate horror stories. I want output like below Hi iam author... (3 Replies)
Discussion started by: vinothsekark
3 Replies

5. Shell Programming and Scripting

Conditional removing of words from a line

Hi , I have a .csv file,from which I want to remove some data from each column as below. Source Data GT_12_AUDIT,SCHEDULED,NOZOMI2010/GT_12_AUDIT,CTSCAN/Zh_GT_6547887/GT_12_AUDIT,CTSCAN/Zh_GT_6547887... (3 Replies)
Discussion started by: gaur.deepti
3 Replies

6. Shell Programming and Scripting

finding and removing 2 identical consecutive words in a text

i want to write a shell script that correct a text file.for example if i have the input file: "john has has 2 apples anne has 3 oranges oranges" i want that the output file be like this: "john has 2 apples anne has 3 oranges" i've tried to read line by line from input text file into array... (11 Replies)
Discussion started by: cocostaec
11 Replies

7. Shell Programming and Scripting

Removing identical words in column

I have a file that needs to be cleaned up. Here is the file: Project Project John Project Gary Project Sean Project2 Project2 Lisa Project2 Tyler Project2 Sam Project3 Project3 Mike Project3 Bran I need the o/p to be: Project John Gary Sean Project2 (7 Replies)
Discussion started by: leepet01
7 Replies

8. Shell Programming and Scripting

Searching for lines in textfiles

Hello all, I've a problem. I've two logfiles and i need to find lines in the second file by using information from the first file. First I need to extract a searchpattern from the first file. Its like abc=searchpattern&cde=. All between abc= and &cde= is the pattern I need to find in the second... (2 Replies)
Discussion started by: Avarion
2 Replies

9. Shell Programming and Scripting

removing 2 words from file.

Hi All, I have a text file with name of source files in that. source files ends with .mxml and .css. Now I want to remove the extensions of these source files. Currently I can do so by writing 2 sed commands, as there are files with just 2 different extensions. But I want to do it in one sed... (6 Replies)
Discussion started by: mkashif
6 Replies

10. UNIX for Dummies Questions & Answers

How to replace a string in multiple textfiles?

Hello I'm trying to replace a string in multiple text files using the tcsh shell. For example I've got some files called test1 test2 test3 etc. Each of them contains "Hello World". Now I want to replace each "Hello" with "Howdy" using sed and a foreach loop. I tried the following but it... (1 Reply)
Discussion started by: dwidmer
1 Replies
Login or Register to Ask a Question