replacing all 4 first upper char of every rec to lowercase ?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers replacing all 4 first upper char of every rec to lowercase ?
# 1  
Old 08-02-2006
replacing all 4 first upper char of every rec to lowercase ?

I have a file where some records have been updated the wrong way and need to fix it quickly since the amount can be alot.

Every record where any of the first 4 characters are in upper case need to be changed to lowercase.

Records can have '#' in position-1 for comments. These musn't be changed.

How do I do it with VI ?

If not with VI, with what and how ?

Last edited by Browser_ice; 08-02-2006 at 11:34 AM.. Reason: error
# 2  
Old 08-02-2006
can you move this thread to the right place ?

it got posted in the wrong place by mistake
# 3  
Old 08-02-2006
Gosh, I'm not sure if this can be done in vi but here's how to do it via awk:

Code:
nawk '{
    sub(/^[A-Z][A-Z][A-Z][A-Z]/, tolower(substr($0,1,4)) substr($0,5),$0)
} 1' yourfile > newfile

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk sed to repeat every character on same position from the upper line replacing whitespace

Hello is it possible with awk or sed to replace any white space with the previous line characters in the same position? I am asking this because the file I have doesn't always follow a pattern. For example the file I have is the result of a command to obtain windows ACLs: icacls C:\ /t... (5 Replies)
Discussion started by: nakaedu
5 Replies

2. UNIX for Beginners Questions & Answers

Help with replacing a char

Hello All, I have a file as below . I want to convert the Y with numbers to H From 4, M11, P2521759, Y75,Y70,Y105,Y110,Y700,Y815,Y830,Y900,Y162,Y300, Y291,Y290,Y15,Y20, MR2716014,MR2617014, Yesterday,current 1,201012, 102032,1 11112,0 to 4, M11, P2521759,... (2 Replies)
Discussion started by: arunkumar_mca
2 Replies

3. UNIX for Dummies Questions & Answers

Convert lowercase to upper case in Sparc

Hi, I need to convert the hostname to uppercase and attach it to a string. eg: $hostname output mymac Final output should be Production.MYMAC (3 Replies)
Discussion started by: mohtashims
3 Replies

4. Shell Programming and Scripting

Problem with upper and lowercase in awk

My awk (GNU Awk 3.1.8 on Ubuntu 12.04) seems to ignore case. cat file abc ABC aBc 123 awk '//&&//{print $0,"";next}{print $0,""}' file My result:abc ABC aBc 123 Correct result:abc ABC aBc 123 (6 Replies)
Discussion started by: Jotne
6 Replies

5. UNIX for Dummies Questions & Answers

Change lowercase to upper case

dear all, i have file input ABCDE_Asta_Key_Park,COJ050,10.142.3.150 C_BDEFG_City_Lake,C_BIR0,10.135.3.6 C_FDGEBIR_Axaudia,C_ABIR1,10.135.3.34 I want to change lowercase in to uppercase for all strings output ABCDE_ASTA_KEY_PARK,COJ050,10.142.3.150 C_BDEFG_CITY_LAKE,C_BIR0,10.135.3.6... (5 Replies)
Discussion started by: radius
5 Replies

6. Shell Programming and Scripting

SED (or other) upper to lowercase, with first letter of first word in each sentence uppercase

The title pretty much defines the problem. I have text files that are all in caps. I would like to convert them to lowercase, but have the first letter of the first word in each sentence in uppercase. I already have SED on the server for fixing / tweaking text files, but I'm open to other... (5 Replies)
Discussion started by: dockline
5 Replies

7. UNIX for Dummies Questions & Answers

AWK - changing first char from small to upper

I need to write script in AWK, changing first char from a line from lower to upper. I found function toupper etc. but have no idea how to sent only first char from every line instead of the whole line. Anyone has any idea? // Sorry for my english:D (8 Replies)
Discussion started by: bbqtoss
8 Replies

8. Shell Programming and Scripting

Convert lowercase to upper case based on certain conditions

Hello Unix Gurus : It would be really great if a solution can be found Following is the condition on Solaris Change all the records to upper case ignore the case for records having "A2B2 " in them . how can i use nawk or any other command Following is the SAMPLE INPUT... (6 Replies)
Discussion started by: tsbiju
6 Replies

9. Programming

replacing char with string

how we can replace char with a string example char *a="a.s" so finally what i ant to do raplace a with ant and s sree so in my array a i want to store the value as "ant.sree" thank u in advance (1 Reply)
Discussion started by: phani_sree
1 Replies

10. Shell Programming and Scripting

after i convert upper case to lowercase

If user chosen to tolower then it should convert file name to lower or vice versa. when file names converted it should put into appropriate subdirectories. e.g when files converted it then seperate them out with file etension where it will seperate them out . such as file.pdf, phone.doc both... (1 Reply)
Discussion started by: Alex20
1 Replies
Login or Register to Ask a Question