Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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 have a file containing some data as in the following example:

data1: it is my data
data2: some more data
data3: even some more data

What I want is the following output in another file:

it is my data
some more data
even some more data

Please guide me how to do it!

share|improve this question
should be migrated to – i08in Mar 9 '14 at 10:23
@Jobin why it should be migrated to – Avinash Raj Mar 9 '14 at 12:14
@AvinashRaj: This is not specific to Ubuntu. – i08in Mar 9 '14 at 12:15
you didn't see any bash scripting commands before in AU? – Avinash Raj Mar 9 '14 at 12:17
up vote 9 down vote accepted

This should work:

sed -i .bak 's/[^:]*: *//' file

Explanation: The -i .bak will edit the file in place, and create a backup of the original called filename.bak. s/pat/replacement/ means substitute pat with replacement. [^:]*: * means match the longest string of non-: characters, followed by a : then one or more space. The final result is that it will delete everything up to the first : and following spaces.

This approach has the advantage of working with data: or foo: or whatever and will also work if you have multiple : on the same line. For example, it can deal with this:

data: a line that contains : a colon!
share|improve this answer

It's very simple if you use awk:

awk -F ': ' '{for (i=2; i<=NF; i++) print $i}' file_name > new_file_name

Each line is separated in more fields using ': ' as separator and print everything except the first field. The output is redirected to the new_file_name.

share|improve this answer
@Aditya he set the delimeter as : and awk considers the words before : as column 1 and the remaining part as column 2.After that the words from the column 2 are writed inside new_file. – Avinash Raj Mar 8 '14 at 17:38
@Radu am i correct? – Avinash Raj Mar 8 '14 at 17:40
@AvinashRaj You are very correct, thank you :) – Radu Rădeanu Mar 8 '14 at 17:47
@Aditya note that this will not work if your lines can contain more than one :. If that is possible use my solution below. – terdon Mar 8 '14 at 17:50
@terdon Now will work ;) – Radu Rădeanu Mar 8 '14 at 17:54

This looks like a job for cut

cut -d: -f2- file > new_file
share|improve this answer

You can use Vim in Ex mode:

ex -sc '%s/[^:]*: *//|x' file
  1. % search all lines

  2. s substitute

  3. x save and close

share|improve this answer

Open the file in vim editor as follows:

vi <filename>

and then press esc and then the following:

:%s/data.: //gc

Here %s is used for string replace

/ is the delimiter between the command and the strings

data.: is the first string, . is used for any single character gc is used to find and confirm before replacing

share|improve this answer
please tell me a link where I could learn stuff about vi editors since it looks very promising. – Naseer Ahmed Mar 9 '14 at 9:56
@khan: Google is the best thing I could think of. May be you could start off here. – i08in Mar 9 '14 at 10:08

Your input file looks like an output of a grep command, say:

grep data data*

If this is really the case, you can use the -h option of grep command itself to get what you need:

grep -h data data*
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.