Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a file with columns of the form

number_number  number  columns of numbers

I want to extract the columns beginning with particular numbers. I tried the following, but get nothing in output:

sed -n 's/14_90 2275.*/&/p'

What is wrong with my command?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Why don't you use grep which is the right tool for your case? Here is an example to list the files which starts with 14_90 2275:

grep '^14_90 2275' filename

If you still want to use sed, than the right command is:

sed -n '/^14_90 2275/p' filename

If the white spaces are tabs, then you should use:

grep $'^14_90\t2275' filename

respectively:

sed -n '/^14_90\t2275/p' filename

Or better:

grep $'^14_90\s2275' filename

respectively:

sed -n '/^14_90\s2275/p' filename

to match any whitespace characters (space, tab etc.).

share|improve this answer
    
Thanks for your example. In fact, I am reading a tutorial on sed and would like to train using it... –  bigTree Mar 24 at 13:22
    
I just tried this command (with grep )and it doesn't output anything... The columns are separated by tabs but I tried adding a \t and it didn't work neither –  bigTree Mar 24 at 13:25
    
@bigTree I edited my answer to see how you can match any whitespace characters (space, tab etc.). –  Radu Rădeanu Mar 24 at 13:42

Your Answer

 
discard

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.