LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 01-19-2011, 09:23 AM   #16
bcrawl
LQ Newbie
 
Registered: Jan 2011
Posts: 11

Original Poster
Rep: Reputation: 0

hey guys. every one of the above commands worked. Thanks a lot. I have instantly got the awk example from druuna/schenidz but working on sed ones from other guys. But they all work magically. My terminal shows 5 different commands which operate on the same file and give the same output. pretty awesome.
 
Old 01-19-2011, 09:38 AM   #17
bcrawl
LQ Newbie
 
Registered: Jan 2011
Posts: 11

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by grail View Post
Based on sycamorex's sed:
Code:
sed -rn 's@</?mfr_id>@@gp' file
could someone please explain the command. How is it extracting it? Is it stripping <mfr_id> and </mfr_id> and leaving the digits or is it extracting the digits...and how does it differ from this one. This will help me understand the process a little bit.

Code:
sed -nr '/mfr_id/ s:[^[:digit:]]*([[:digit:]]+).*:\1:p'
Thanks.
 
Old 01-19-2011, 09:47 AM   #18
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Quote:
Originally Posted by bcrawl View Post
hey guys. every one of the above commands worked. Thanks a lot. I have instantly got the awk example from druuna/schenidz but working on sed ones from other guys. But they all work magically. My terminal shows 5 different commands which operate on the same file and give the same output. pretty awesome.
Hi,

As usual in Linux, there's always more then one way to skin a cat I have learned lots from this thread thanks to the gurus here at LQ. Thanks guys.

Kind regards,

Eric
 
Old 01-19-2011, 04:14 PM   #19
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,119

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
The first sed example strips out (specifically) what is known to be not wanted - it substitutes "null" for it.
The latter case ensures only non-digits start the record, and looks for a string of digits - followed by anything (which could include digits). The bit in parentheses - the string of digits in this case - is retained by the back-reference "\1".

Obvious ain't it .... . You have to be real careful constructing regex so you don't get unintended results. We've all been there.

Last edited by syg00; 01-20-2011 at 06:57 AM.
 
Old 01-19-2011, 07:52 PM   #20
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
@ sycamorex , druuna
Code:
grep mfr_id <input-file> | awk -F "[><]" '{print $3}'
it was really not meant as a full solution but rather a code snippet to point the original poster in the right direction...

and the nit-picky award goes to...
 
  


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
grep help or sed or awk dmchess Linux - Software 4 09-29-2010 06:53 PM
[SOLVED] Help using awk,sed and grep shakes82 Programming 34 07-07-2010 11:12 PM
help with grep/sed/awk nikunjbadjatya Programming 8 02-17-2010 07:29 PM
awk/sed to grep the text ahpin Linux - Software 3 10-17-2007 12:34 AM
Newbie SED / AWK / Regex command help request Critcho Linux - Newbie 10 03-19-2007 11:22 AM

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

All times are GMT -5. The time now is 04:08 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