LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 08-05-2011, 11:33 AM   #16
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,838

Rep: Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822

I don't have access to a "strict" Unix system, hence my reference to OpenSolaris - which is probably (much) closer to Gnome/Linux.
I can only test what I have - gawk extensions suffer the same exposure. Thanks @anomie for the testing.
 
Old 08-05-2011, 11:37 AM   #17
nicomoresi
LQ Newbie
 
Registered: Aug 2011
Posts: 11

Original Poster
Rep: Reputation: Disabled
@anomie

Sorry for the inconvenience (I'm new).
Started as a Linux consulting and changed to *NIX
 
Old 08-06-2011, 08:02 AM   #18
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,606

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Quote:
Originally Posted by nicomoresi View Post
@anomie

Sorry for the inconvenience (I'm new).
Started as a Linux consulting and changed to *NIX
Hi,

glad you got it solved. Since it has been suggested that sed might be an appropriate tool
I would like to convey some thoughts on the use of 'sed' to emulate 'grep -io':
With GNU-sed available you could do something like this
Code:
sed -n 's/\(match\|alternate\)/\1\n/i;s/.*\(\(match\|alternate\)\n\)/\1/I;T;P;D' file
The problem when you do not have GNU-sed is the 'I' or 'i' flag at the end of the 's' command.
This tells sed to match case-insensitive. So it is likely that you do not have this option on Solaris.
You can bypass this by using the 'y' command; you will lose capitalization, though
Code:
sed -n 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
s/\(match\|alternate\)/\1\n/;s/.*\(\(match\|alternate\)\n\)/\1/;ta;b;:a P;D' file
If one is restricted to posix options only then you can't even use the logical '|' operator.
The second sed does not yield any results. However, I see that you used
Code:
sed -e "s/.*\(Cisco\|Motorola\|Arris\).*/\1/"
If this did return some matches then this suggests that Solaris-sed is somewhere between posix and GNU. If this is the case then maybe you have even case-insensitive matching; i.e. you can use the 'i' or 'I' flag at the end of the 's' command.

Finally, a posix only solution:
Code:
sed -n --posix 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
	/^\n/ {
		s/^\n//
		s/\n\n/\n/g
		p
		b
	}
	s/\(.*\(match\).*\)/&\n\n\2/
	s/\(.*\(alternate\).*\)/&\n\n\2/
	D

' file
If you run this on the sample data I provided in a previous post then you will see that you lose capital letters and that the results are not in order.

As I already stated, I do not have Solaris. So if you have some spare time on your hands and like to have some "fun" with sed then you can venture into exploring the limitations of Solaris-sed and determine for yourself if it is worth the trouble.
If you do so then some feedback would be nice, so that we might be able to suggest more appropriate Solaris-sed solutions in the future.

Last edited by crts; 08-06-2011 at 08:05 AM.
 
1 members found this post helpful.
Old 08-08-2011, 09:00 AM   #19
nicomoresi
LQ Newbie
 
Registered: Aug 2011
Posts: 11

Original Poster
Rep: Reputation: Disabled
@crts

Thank you for your sed help, has been very helpfull... I just have something to show you, that I think it doesn't works.

Code:
[root@cpe-172-16-0-136:~]# echo "SNMPv2-MIB::sysDescr.0 = STRING: Cisco IOS Software, 7200 Software (UBR7200P-JK9SU2-M), Version 12.2(33)SCB4, RELEASE SOFTWARE (fc1)" |  sed -n 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'
[root@cpe-172-16-0-136:~]#
It doesn't return nothing, it's this because of the numbers?
 
Old 08-08-2011, 09:07 AM   #20
nicomoresi
LQ Newbie
 
Registered: Aug 2011
Posts: 11

Original Poster
Rep: Reputation: Disabled
We can remplace:
Code:
sed -n 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'
with :
Code:
tr [:upper:] [:lower:]
 
Old 08-08-2011, 12:13 PM   #21
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,606

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Quote:
Originally Posted by nicomoresi;4436742
[code
[root@cpe-172-16-0-136:~]# echo "SNMPv2-MIB::sysDescr.0 = STRING: Cisco IOS Software, 7200 Software (UBR7200P-JK9SU2-M), Version 12.2(33)SCB4, RELEASE SOFTWARE (fc1)" | sed -n 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'
[root@cpe-172-16-0-136:~]#
[/code]

It doesn't return nothing, it's this because of the numbers?
Hi,

the above 'sed' does not return anything because of the '-n' option. It instructs 'sed' to not print anything by default. Printing only happens if when the 'p' command is encountered, e.g.
Code:
sed -n 'y/ABC/abc/; p'
However, if you only want to convert upper to lower case then the 'tr' command is indeed the better choice.
 
  


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 07:53 PM
[SOLVED] Help using awk,sed and grep shakes82 Programming 34 07-08-2010 12:12 AM
[SOLVED] Awk/Sed incremental replace Euler2 Programming 5 06-30-2010 01:27 PM
help with grep/sed/awk nikunjbadjatya Programming 8 02-17-2010 08:29 PM
awk/sed to grep the text ahpin Linux - Software 3 10-17-2007 01:34 AM


All times are GMT -5. The time now is 10:38 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration