Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
sed by default prints the pattern space - that basically means everything it sees.
You're on the right track - look at the manpage. You need "-n" to suppress the printing, but then you need to tell it to print your selected records. Takes some testing to figure it out.
sed is not the way to go for this. Consider this file:
Code:
line1
line2 maTch
line3 alternate
line4 mAtch me and alternatE eol
line5 alternate me and matCh reverse
Several possible matches in one line are hard to identify via RegEx. The Solaris version of 'sed' is also very limited and probably does not have switch for case-insensitive matching.
I don't know about the limitations of awk on solaris but this one worked:
Code:
awk 'BEGIN{IGNORECASE=1}{ for (i=1;i<=NF;i++){if ($i ~ "match|alternate"){ print $i}}}' file
The bold part are your possible matches. Adjust them accordingly.
[root@cpe-172-16-0-137:~]# uname
SunOS
[root@cpe-172-16-0-137:~]# echo " aaa Motorolabbbb" | awk 'BEGIN{IGNORECASE=1}{ for (i=1;i<=NF;i++){if ($i ~ "Cisco|Motorola|Arris"){ print $i}}}'
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: bailing out near line 1
[root@cpe-172-16-0-137:~]#
On the contrary, sed is (probably) a better tool for this. Works on my old OpenSolaris too.
But then so does grep -o ... :shrug:
How would you make a case-insensitive match for the 's' command on Solaris? According to my documentation this is a GNU extension, so I assume that it is not available on Solaris. Is it possible that you have also GNU-sed installed on your Solaris?
That will read from stdin, and print case-insensitive matches. As written, it only prints one occurrence of cisco, motorola, or arris per line. (If one or more of those could occur several times on a line, the script needs a little tweaking.)
-------
P.S. It's a good idea to post your OS / version when starting a thread! This is not even a Linux question.
-------
BTW, should you want to match more than once per line, it's a simple matter of the following. (Just tested it.)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.