problem with loop bash
hi
i wrote this code: the code print how much file in the sub folder logs,which end with inout.log. , contain "hello" word at least one time however the code does not work for me(it does not print anything)...any ideas please? thanks alot Code:
#!/bin/bash |
cat $line | grep "hello" sends the contents of a file called $line (which almost certainly does not exist) to grep.
Incidentally, you probably don't want the "." after log. This would do what you want in one line: grep hello logs/*inout.log | wc -l |
thanks you
can you explain me, what does the command "wc -l" ? |
Try your man pages.
|
For reference, you would have been closer to your goal using echo instead of cat
Code:
echo $line | grep "hello" I don't think catkin's example does what you want either. catkin's example will give you the total number of lines on which 'hello' appears but when I read what you've written I think that you want the number of files in which hello appears. The two things are only the same if no file contains more than one line that contains 'hello'. What you've written does leave some room for interpretation. Assuming I'm correct (which I might not be), then I think you want is Code:
$ grep -l hello logs/*inout.log | wc -l Code:
$ grep hello logs/*inout.log Code:
$ grep -l hello logs/*inout.log |
hi
thanks for help i tried to run all the three codes that you wrote... (i have a file which named "1.inout.log" in "logs" directory and i wrote then hello man... so the output of file must be 1...which does not seems to be like) moreover,there is an error, please read the output: Code:
3.3: line 3: $: command not found |
You've completely changed the content of your post since I got the email notification. If you'd edit posts it's a good idea to say you've done it and why.
Most of what you currently have in the post as I'm writing this doesn't make any sense to me but I can tell you that you should not include the $ in my examples. The $ represents the command prompt. Your command prompt ,any not actually be a $ but it's a long standing convention used when giving example commands to use $ to represent the command prompt. tl;dr don't type the $ |
my mistake, the first code do it
thanks alot i really appreciate your help |
Post the output you get from each of the three commands. At least one of them should give output which is different to the other two. I believe one of the commands should give the output you want.
|
Post 8 was completely rewritten whilst I was composing post 9.
|
ok thanks,,
maybe do you have any ideas for this problem: http://www.linuxquestions.org/questi...730/page2.html |
All times are GMT -5. The time now is 10:23 AM. |