LinuxQuestions.org
Review your favorite Linux distribution.
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-13-2017, 11:34 AM   #1
chtsalid
Member
 
Registered: Jan 2017
Posts: 69

Rep: Reputation: Disabled
Perform a case-insensitive search for a pattern


Hi guys,

how can I perform the following?

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.

Many thanks!
 
Old 01-13-2017, 11:47 AM   #2
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,303
Blog Entries: 7

Rep: Reputation: 400Reputation: 400Reputation: 400Reputation: 400Reputation: 400
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.

Some additional reading that may help:
LQ Search
LQ Sitemap
LQ Site FAQ
How to ask technical questions to get quality answers
 
1 members found this post helpful.
Old 01-13-2017, 01:26 PM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,838
Blog Entries: 13

Rep: Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893Reputation: 4893
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.
 
1 members found this post helpful.
Old 01-13-2017, 01:58 PM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
When is the test?
 
1 members found this post helpful.
Old 01-13-2017, 06:09 PM   #5
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,303
Blog Entries: 7

Rep: Reputation: 400Reputation: 400Reputation: 400Reputation: 400Reputation: 400
Quote:
Originally Posted by Habitual View Post
When is the test?
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).
 
1 members found this post helpful.
Old 01-14-2017, 02:34 AM   #6
chtsalid
Member
 
Registered: Jan 2017
Posts: 69

Original Poster
Rep: Reputation: Disabled
Hi all,

thank you for your input. Here is what I did.

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

Thanks!
 
Old 01-14-2017, 04:14 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,988

Rep: Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182
Thanks for the reply and effort

Here are a few pointers:

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:
Code:
man grep

Let us know how you get on?
 
1 members found this post helpful.
  


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
[SOLVED] Case insensitive Sharath Ravi Linux - Newbie 7 04-22-2014 03:51 AM
how to search in VI wih case insensitive lordofring Programming 7 11-16-2011 09:11 AM
SED - case insensitive pattern restriction filip Linux - General 3 07-28-2009 09:08 AM
Copying files from case-sensitive Linux to case-insensitive Windows via CIFS? SlowCoder Linux - General 4 05-07-2008 08:03 PM
case insensitive search command ColKurtz Linux - Newbie 4 01-20-2005 08:02 AM

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

All times are GMT -5. The time now is 10:05 PM.

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