LinuxQuestions.org
Visit Jeremy's Blog.
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, 10: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, 10:09 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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, 10: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, 10:34 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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 09:16 PM
grep string with space (2 word string) casperdaghost Linux - Newbie 7 08-24-2009 03:11 AM
How to grep for a string in a file kaprasanna Linux - Newbie 3 01-06-2009 07:29 AM
grep the exact string only ZAMO Linux - General 11 08-28-2008 06:08 AM
how to grep only one string pr match gummimann Linux - General 3 11-06-2003 10:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:28 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration