LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-26-2012, 11:03 AM   #1
Eppo
Member
 
Registered: Feb 2007
Location: NY
Distribution: Arch, Ubuntu
Posts: 77

Rep: Reputation: 27
sed command not matching?


ok, so i'm trying to match this line with sed:

Code:
Sales ID: JWM/NZF                                      Period Ending: 03/17/2012
or this line:
Code:
Sales ID: NZF                                      Period Ending: 03/17/2012
so if i use this:
Code:
sed -n '/Sales ID:\s\w\w\w\/'NZF'/,/Totals:/p'
it will match fine, but i would like to capture a 2 word character ID before the /.
so if i try use replace the \w\w\w with \w+ it doesnt work, and if i try to replace it with \w{2,3} it also doesnt work.
What am i doing wrong
Thanks for your help.

Joe
 
Old 03-26-2012, 11:26 AM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Try escaping the brackets:
Code:
$ sed -n '/^Sales ID:\s\w\{2,3\}/p' input.txt

Last edited by anomie; 03-26-2012 at 11:29 AM.
 
Old 03-26-2012, 12:10 PM   #3
Eppo
Member
 
Registered: Feb 2007
Location: NY
Distribution: Arch, Ubuntu
Posts: 77

Original Poster
Rep: Reputation: 27
Worked like a charm.
Thanks
 
Old 03-26-2012, 12:11 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
As the second example doesn't have a slash in the same spot ... what should be returned? ie. still both lines?
 
  


Reply



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
sed and regexp matching (GNU sed version 4.2.1) Ashkhan Programming 8 02-27-2012 09:12 AM
[SOLVED] Pattern matching with sed vinaytp Linux - Newbie 3 05-24-2010 07:33 AM
Sed command to print matching lines and 2 lines above.. DX398 Programming 12 10-01-2008 08:25 AM
Sed pattern matching digitalbrutus Programming 1 08-20-2006 01:37 PM
sed matching an apostrophe dazdaz Linux - General 2 04-28-2006 05:24 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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