LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   grep a particular string (https://www.linuxquestions.org/questions/linux-newbie-8/grep-a-particular-string-773990/)

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:
Quote:

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

{+123456789123456789+} {+456789+}
{+1234+}

PLease advice experts

JOhn

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:
Code:

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,

Quote:

{+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+}
{+1234+}


THanks

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.