-   Linux - Newbie (
-   -   grep a particular string (

john83reuben 12-07-2009 09:03 AM

grep a particular string
Hi all,

lets say i have a file called file.txt which has the following values:

{+123456789123456789+} john {+456789+}
{+1234+} jo
I want to do grep so that the result is

{+123456789123456789+} {+456789+}

PLease advice experts


pixellany 12-07-2009 09:09 AM

grep is typically not used to edit files---its main purpose is to find things.

What is the rule for your case? I appears (maybe) that you just want to remove text, but leave numbers.

You could try:

sed 's/[[:alpha:]]//g'

john83reuben 12-07-2009 09:14 AM

Actually I am doing a comparison script,

I have redirect the output of a wdiff command into a file called file.txt,


{+123456789123456789+} john {+456789+}
{+1234+} jo
So what I would like to do is to grep file.txt by using regex to have only

{+123456789123456789+} {+456789+}


pixellany 12-07-2009 09:34 AM

You appear to have not read my post!!!

I asked you for the rule to be followed (and I suggested what I thought it might be)---It does not matter where the data comes from---we are just working with the data you showed us.

I also told you that grep might not work. But actually, it might: Look at the -o and -v options.

But SED is easier----did you try it?

All times are GMT -5. The time now is 09:53 AM.