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

Hello I have one file with output

Name        : ABC
Name        : CDE
Name        : ZYS

I want to get the result


How can i get it through SED command.

I have tried. sed s/'Name' but it returns me the output like: ABC

I want to trim the space and also : from the string.

share|improve this question
up vote 7 down vote accepted

You can use awk for this:

awk '{print $3}' yourfile

This simply prints the third field/column for every record/row.

share|improve this answer
Yes thats correct :) thanks – Moiz Apr 17 '13 at 6:50

If you use sed:

sed 's/^.*: //' yourfile

or to be a bit more precise:

sed 's/^Name[^:]*: //' yourfile

share|improve this answer
take care, the first one is greedy and eats too much if there's a ': ' in the part right of the first ':'. – reto Apr 17 '13 at 12:18

With recent GNU grep versions you could do it like this with positive lookbehind:

grep -oP '(?<=: ).*' infile

Or more portably:

grep -o ':.*' infile | grep -o '[^ ]*$'


share|improve this answer

To complete the other answers with another way:

cat file | cut -d: -f 2- 

you can cut out the remaining whitespace

cat file | cut -d: -f 2- | cut -c 2-

Or more compact, a bit less readable:

cut -d: -f 2- < file | cut -c 2-
share|improve this answer
No need to use cat here. cut -d: -f 2- file works. – Evan Teitelman Apr 17 '13 at 12:35
good point, thamks! – reto Apr 17 '13 at 12:59

You can use the awk command below:

awk -F ':' '{print $2}' 
share|improve this answer

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.