hi
thanks you i found a solution... i have one more problem... if i have a input file that stored in the path: tests\input.in the bash recognize it as a full name of input, it wrote to me: "./testInOut: line 5: tests/input.in.in: No such file or directory" as i understand ' the bash thinks that the path which i provided, this is the input file name: "tests/input.in" how can i wrote to the bash that this is a path to the input file and the input file is only input.in? thanks alot |
Quote:
Is the directory tests/ or test/? |
thanks for the advice
i edit my post (i mean tests directory) please, soeone can help me? |
i have one more question:
i wrote this code: Code:
#!/bin/bash however my script doesnt work any ideas? |
"*" is a reserved shell character, the basic glob. You have to quote the grep string to protect it. But also, grep uses regular expressions, not globbing patterns, so you need to use ".*" instead. You may also want to anchor the string to the start and end of the line.
Finally, Useless Use Of Cat. Code:
grep '^==.*==$' 1.memory.log |
Quote:
|
"read" can do do the proper assignments on it's own.
Code:
IFS='@' Instead one ask per thread. Makes it easier and can be easily searched provided you named the thread properly. |
Quote:
first of all, i send a report to the admin, i hope he will change the title soon. moreover, i wrote your code however it does not work for me...any ideas? and please someone post a solution to my second problem...i didnt find any solution for it Quote:
|
Quote:
|
Quote:
hi thanks everybody i still have a problem regarding this issue..please let me know if there is any solution for it... hi catkin, regarding the last problem i solved it...thanks everybody |
Sorry, I can't see any problems with it, and it works for me.
Please show us an actual example of the text that needs to be matched, and the exact commands you've used including the output you get, if any. |
hi the directory logs contains a file which named 1.memory.log and
it wrote there ==24031== so the output must be 24031. however the output of your code is empty.. and other suggestions? thanks |
Again, use code tags around all of your actual code or data, and cut&paste wherever possible to capture the exact text, including any non-printing characters. The true format of the text can be very important in cases like this.
As I suspected, your actual requirements are different from what you described. You want to capture the part between the equal signs, not just match the line itself. grep's only function is to search for regex patterns within lines of text, and output either the entire line or the entire matched pattern (with the -o option). It can't extract substrings from a given pattern. The pattern I gave above is for matching an entire line. If a line starts (^) with two equal signs, and ends ($) with two equal signs, then that whole line will match and print. So you should at least be getting the entire line in the output. If you're matching nothing, then there's something about the file or the command you used that you still haven't shown us. Again, cut&paste the exact file contents and the output of your terminal, in code tags. But in any case you can't extract the number in the middle this way. To extract a substring from a regex pattern, you have to use sed (or perhaps awk) instead. Those tools provide the line-editing ability needed to separate the parts you want from the parts you don't want. Code:
sed -rn '/^==/ s/^==([^=]*)==$/\1/p' file You really need to take some time to learn how to use regular expressions if you intend to do a lot of text manipulation like this. They are supported by a large number of scripting tools like these. A couple of quick regular expressions tutorials: http://mywiki.wooledge.org/RegularExpression http://www.grymoire.com/Unix/Regular.html You should also familiarize yourself with the tools you're using. Take some time to look at the info pages for grep, sed, awk, find, and the coreutils, at the very least. The grymoire site also has pretty good tutorials of some of these tools: http://www.grymoire.com |
All times are GMT -5. The time now is 12:20 PM. |