Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am having a CSV file containing 3000+ lines in the following format:

R1C1, ABC123abc, R1C3
R2C1, DEFG456defg, R2C3
R3C1, HIJKL789hijkl, R3C3

I need to remove all the capital letters from the second column of the file so that it reads as follows:

R1C1, 123abc, R1C3
R2C1, 456defg, R2C3
R3C1, 789hijkl, R3C3

How can this be done?

share|improve this question
up vote 2 down vote accepted

You can use awk:

$ awk -F',' '{sub(/[[:upper:]]+/,"",$2)}1' OFS=',' file
R1C1, 123abc, R1C3
R2C1, 456defg, R2C3
R3C1, 789hijkl, R3C3
share|improve this answer
Thanks! What if I want to remove string before first alphabet in small caps? For example: R1C1, abc, R1C3 in this case. – Mandar Shinde Aug 1 '14 at 3:22
In this case, it can be sub(/[[:upper:]]+[[:digit:]]+/,"",$2). – cuonglm Aug 1 '14 at 3:27
In case, if I need to mention multiple strings in the regex part, like ABC,DEFG,HIJKL, then how can I do that? – Mandar Shinde Aug 1 '14 at 3:49
[[:upper:]]+ matches all of them. If you want string literal, ABC|DEFG|HIJK. – cuonglm Aug 1 '14 at 3:53

if the second field has capitals scattered,

awk -F ',' '{gsub(/[[:upper:]]/, X, $2)}1' OFS=, file
share|improve this answer

Bash in combination with sed:

while IFS=, read a b c; 
 echo -n $a ; cnt=$[cnt+1]; 
 sed  -e 's/[^,]*,\([^,]*\).*/\1/' file | 
 sed  -e 's/\([[:upper:]]\)//g'| 
 sed  -e  $cnt'q;d'|
 tr '\n' ' ' ;
 echo  $c; 
done  < file


R1C1 123abc R1C3
R2C1 456defg R2C3
R3C1 789hijkl R3C3
share|improve this answer
Downvoter comment? – Ruslan Gerasimov Aug 1 '14 at 10:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.