[SOLVED] Perform a case-insensitive search for a pattern
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.
Perform a case-insesitive search for the pattern 'then' in the /etc/profile file and save the result in the /var/tmp/pattern.txt. Make sure that empty lines are not included.
Hello and welcome to LQ. Please note the thread you started doesn't meet the minimum threshold that would enable us to help you. We understand that Linux can be intimidating for new members, and we really do want to help. That said, please understand that LQ is not a help desk, customer service line for a product you purchased or willing to do your homework (although we are happy to assist you with specifics, if you show some effort of your own!). We're a 100% volunteer organization that wants to help you help yourself.
Here are a couple tips that will enable us to help you moving forward:
Before posting, have you used the search function to ensure your question hasn't been asked before?
When asking a question, be sure to provide as many relevant details as possible. You should include the distribution and version you're using, along with hardware details, application version and exact error messages where applicable.
Using a descriptive title will vastly increase the number of members who see your thread, and therefore make a response significantly more likely.
If you're actively troubleshooting an issue you should also include any steps you've already taken.
You may want to include how what you are experiencing differs from what you expected to experience.
You can edit your post by clicking the EDIT button in the bottom right corner of your message.
If you are unwilling or unable to ask questions in a manner that allows us to help you, it's unlikely our community will be able to provide you a solution. Unfortunately, serial offenders who show wanton disregard for this request after multiple pointers may be asked to seek help elsewhere. We truly hope that isn't necessary, and assure you Linux and Open Source are extremely rewarding and well worth the learning curve in the long run.
Firstly show what you have tried so that others can understand your expertise as well as how far along with this effort you are.
Check the arguments available for the grep command, you'll notice a lot of capabilities regarding case sensitivity as well as conditioning the output to a form which you'd like to see.
I'm assuming you have some familiarity with using the grep command in the first place, likely that is an answer about how to find a string or pattern within a file.
Look up input/output redirection for Linux and likely you'll figure out how to save your result.
Can you tell me something special about the /var/tmp directory which you should be paying attention too?
I'm assuming that this poorly phrased request is only part of the puzzle. Best you explain really what you are trying to accomplish entirely so that others can offer suggestions.
As goumba points out, LQ members are not here for fast food ordering of content, instead we're here voluntarily to help you to learn more about Linux.
Exactly why I highlighted what I did. "Make sure that empty lines are not included" seems to me a homework directive or an order from a superior (likely the former).
The OP showed no work. Very simple using grep, had they bothered to even search the forums as it is a fairly common request (I neglected to highlight that point at well).
Is this a case sensitive search or should I do something more?
[root@rhcsa1 ~]# grep then /etc/profile
if [ "$2" = "after" ] ; then
if [ -x /usr/bin/id ]; then
if [ -z "$EUID" ]; then
if [ "$EUID" = "0" ]; then
if [ "$HISTCONTROL" = "ignorespace" ] ; then
if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
[root@rhcsa1 ~]#
[root@rhcsa1 ~]# touch /var/tmp/pattern
[root@rhcsa1 ~]# grep then /etc/profile > /var/tmp/pattern
[root@rhcsa1 ~]# cat /var/tmp/pattern
if [ "$2" = "after" ] ; then
if [ -x /usr/bin/id ]; then
if [ -z "$EUID" ]; then
if [ "$EUID" = "0" ]; then
if [ "$HISTCONTROL" = "ignorespace" ] ; then
if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
1. Please use [code][/code] tags when showing code or data that requires formatting be kept or to make something more readable
2. You should refrain from using the root account to practice. Whilst your current testing does not affect an important file like /etc/profile, future testing may not be so kind and the root account is unforgiving and in many instances will not ask if you are sure you want to make the changes you might do!!
3. Have you looked at the grep man page? If you did you find there are a great number of switches which grep understands and will assist in your future testing. To launch the page simply type:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.