LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 12-07-2009, 09:03 AM   #1
john83reuben
Member
 
Registered: Oct 2007
Location: Kuala Lumpur,Malaysia
Distribution: Debian Etch, OpenSuse
Posts: 132

Rep: Reputation: 17
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
 
Old 12-07-2009, 09:09 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
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'
 
Old 12-07-2009, 09:14 AM   #3
john83reuben
Member
 
Registered: Oct 2007
Location: Kuala Lumpur,Malaysia
Distribution: Debian Etch, OpenSuse
Posts: 132

Original Poster
Rep: Reputation: 17
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
 
Old 12-07-2009, 09:34 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
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?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to grep a string from all the files under / thomas2004ch Linux - Newbie 23 09-16-2009 08:16 PM
grep string with space (2 word string) casperdaghost Linux - Newbie 7 08-24-2009 02:11 AM
How to grep for a string in a file kaprasanna Linux - Newbie 3 01-06-2009 06:29 AM
grep the exact string only ZAMO Linux - General 11 08-28-2008 05:08 AM
how to grep only one string pr match gummimann Linux - General 3 11-06-2003 09:40 AM


All times are GMT -5. The time now is 01:39 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration