simple Word Capitalization (Title) find/replace


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting simple Word Capitalization (Title) find/replace
# 1  
Old 03-03-2011
simple Word Capitalization (Title) find/replace

Hi!
I'm looking for a simple script, especially a one liner script in tcsh or bash
that will emulate the find/replace in all text apps.

I want to change all uppercase caracters to Title word (in wich only the first caracter is UpperCase and the rest is lowercase)

I can use sed command, but the -y (transformation) doesn't remember positionning.

the -s flag can't do something like : s/(^[A-Z])([A-Z])* /\1[A-Z]\2[a-z] /g

But a text apps I know (TextWrangler on Mac Os X) can do it with a command
using extend egrep (?) : find this: ^([A-Z])([A-Z])* replace by this: \1\L\2\E
where the first pattern isn't change while the rest is Lowered.

Still sed command can't do it

any solution, for simply transforming CAPITAL WORD into Title Word?

Tx a lot

-stef

Last edited by radoulov; 03-03-2011 at 02:37 PM.. Reason: Code tags, please!
# 2  
Old 03-03-2011
Code:
perl -i.bck -pe's/\b[[:upper:]]+\b/ucfirst "\L$&"/eg' file1 [file2 ... filen]

# 3  
Old 03-03-2011
Code:
sed 's/\(^[A-Z])([A-Z]\)* /\1[A-Z]\2[a-z] /g'


Last edited by radoulov; 03-03-2011 at 02:38 PM.. Reason: Code tags, please!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find Word in Column with replace (2)

Dear ALL, I have sample file : 4c:66:41:6b:b5:5f, 00:00,00:00, -22:-25, robert, 10.101.3.119, host1 4c:66:41:2c:c1:5a, 00:00,00:00, -21:-25, 10.101.3.112, host1 4c:66:41:6b:b1:5a, 00:00,00:00, -21:-25, Julia, 10.101.3.113, host1 4c:66:41:2c:c1:5b, 00:00,00:00, -21:-25, 10.101.3.115, host1... (2 Replies)
Discussion started by: gnulyn
2 Replies

2. Shell Programming and Scripting

Find Word in Column with replace

Hi ALL i have file.txt with text : 4c:66:41:6b:b5:5f, 00:00,00:00, -22:-25, users1, 10.101.3.119, host1 4c:66:41:2c:c1:5a, 00:00,00:00, -21:-25, 10.101.3.112, host1 4c:66:41:6b:b1:5e, 00:00,00:00, -21:-25, users1, 10.101.3.113, host1 4c:66:41:2c:c1:5b, 00:00,00:00, -21:-25, 10.101.3.115,... (3 Replies)
Discussion started by: gnulyn
3 Replies

3. Shell Programming and Scripting

Shell Script @ Find a key word and If the key word matches then replace next 7 lines only

Hi All, I have a XML file which is looks like as below. <<please see the attachment >> <?xml version="1.0" encoding="UTF-8"?> <esites> <esite> <name>XXX.com</name> <storeId>10001</storeId> <module> ... (4 Replies)
Discussion started by: Rajeev_hbk
4 Replies

4. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

5. Shell Programming and Scripting

Find and replace a word in all the files (that contain the word) under a directory

Hi Everyone, I am looking for a simple way for replacing all the files under a directory that use the server "xsgd1234dap" with "xsdr3423pap". For Example: In the Directory, $pwd /home/nick $ grep -l "xsgd1234dap" *.sh | wc -l 119 I have "119" files that are still using... (5 Replies)
Discussion started by: filter
5 Replies

6. Shell Programming and Scripting

Replace a word in a string starting with another word

Hi All, I have a file in which a number of lines are starting with similar first word but different next words. I want to replace the any nth word(not 1st or 2nd) with another word. Eg:- My file contains are like this:- Ram is a boy. Ram is a good boy. Ram plays cricket. Here I want to... (2 Replies)
Discussion started by: mukeshbaranwal
2 Replies

7. Shell Programming and Scripting

find replace a pattern and following characters in a word

Suppose that I have a string "one:#red two:#yellow three:#gr'een four:#blu^e" and I want to replace the pattern :# and the following characters in the word with nothing. The output string should look "one two three four" How can I do this with sed. Some points to consider (a) the last word in... (1 Reply)
Discussion started by: superuser84
1 Replies

8. Shell Programming and Scripting

Simple find and replace with AWK

I am trying to write a find and replace script with AWK and I can't seem to get it to work. I need it to find this exact string *P*: and replace the P with a T or just replcare the whole thing with *T*:. this is what I have tried awk 'BEGIN {gsub(/\*P*:/,"\*T*:"); print}' ${INFILE} >... (4 Replies)
Discussion started by: wbshrk
4 Replies

9. Shell Programming and Scripting

A simple find and replace without using any regex (bash)

Hi, I need to do an exact find and replace (I don't want to use regular expressions because the input comes from user). I want to find a line that matches the user's input text and replace it with an empty string. For example, let's say the user enters I love "Unix" and the contents of the... (2 Replies)
Discussion started by: srikanths
2 Replies

10. Shell Programming and Scripting

Find and replace a part of the word in Shell

I have a csv file in which there are numbers like 078976/9XXX 098754/8XXX I want to replace the XXX with null. I want to know the command/code to do this. I know how to replace the whole word/number. But don't know how to replace a part of it. Thanks in advance, Mihir (3 Replies)
Discussion started by: mihirk
3 Replies
Login or Register to Ask a Question