AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Grep ignore case not working9/28/2023 If you are going to use grep, you might try -i instead of character classes for a case-insensitive match. )", as well as the need for quotes around your character sets, so I won't beat you up about those any more. Others have already explained that you should be using a contruct like x="$(grep. ![]() If you use "$ch" then put in something that matched one of your cases, it would have assigned "grep" to x, then tried to execute -o and likely thrown an error. None of your options were "ch", so no lines executed. The $() should work on every fully POSIX compatible shell, but /bin/sh may not be fully compatible, so using a specific shell is a good idea anyway. But be sure to begin your script with #!/bin/bash, as /bin/sh often is another shell than bash where the syntax may not work. In bash you have the nice syntax (which can be nested) x="$(grep -o '' abc.txt|wc -l)" I added quotes, as you get a problem without quotes when your command does not return anything, as x= is a syntax error while x="" is perfectly fine. Which means execute grep|wc in a subshell and assign the result to the variable x. The correct syntax is x="`grep -o '' abc.txt|wc -l`" This of course doesn't make sense, but you can be glad you didn't try something like x=something rm * which would have deleted your files. You're assigning grep to the variable x for running -o abc.txt, as var=something command assigns the variable just for running command. Your problem is not the case statement, but that you're using the variable assignment in a wrong way x=grep -o abc.txt|wc -l echo $x I'm lost as to why the grep statements aren't displaying anything when I put them inside a case statement. I've also tried this (but the results are the same as those of the code above): #!/bin/bashĪ) x=grep -o abc.txt|wc -l echo $x Į) x=grep -o abc.txt|wc -l echo $x The code executes but after I enter the desired vowel nothing is displayed. ![]() The following script works perfectly (a script to print the number of occurrences of the vowel "a" inside the text file "abc.txt"): #!/bin/bashīut I want to implement this for all the vowels so I did this: #!/bin/bash ![]() I wanted to make a shell script that accepts a vowel and prints the number of occurrences of that vowel inside the text file "abc.txt".
0 Comments
Read More
Leave a Reply. |