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 run a command and pipe it through awk as below :

mycommand | awk '{print $1,tolower($3),$4}

This gives me the following output:

fred.o: t .abcdefg 
fred.o: u .rstuvwxy 
fred.o: t .defghi 
fred.o: t .jklmnop 
fred.o: d abcdefg 
fred.o: d zyxwvuts 

As you can see the sometimes the third column contains a leading "." but not always.

How can I modify my awk command to get rid of the leading "." in the third column if it exists ? eg I would like my output to look like this :

fred.o: t abcdefg  
fred.o: u rstuvwxy  
fred.o: t defghi  
fred.o: t jklmnop  
fred.o: d abcdefg  
fred.o: d zyxwvuts  
share|improve this question
mycommand | awk '{sub(/^\./, "", $4);print $1,tolower($3),$4}'
share|improve this answer
This works perfectly and is very elegant too. Thank you Nykakin for your very swift and very helpful response. – signal11 Feb 4 '13 at 17:40
@signal11 If this answer solved your problem, please mark it as accepted by clicking on the checkmark on the left. That is the SE way of expressing thanks. – terdon Feb 11 '13 at 18:07

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.