return and exit (plus more questions about shell scripting)
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.
"*" 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.
By the way, this thread is getting quite far off the topic of the original thread title. But rather than start a new thread, I suggest that you use the the "report" button and ask a moderator to change the title of this one to something more appropriate, like "some questions about scripting".
"read" can do do the proper assignments on it's own.
Code:
IFS='@'
while read description in out;
do
#....
#....
done < theFileContainigThisStuff
And, please, do not extend one thread to handle loads of different problems.
Instead one ask per thread.
Makes it easier and can be easily searched provided you named the thread properly.
"*" 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.
By the way, this thread is getting quite far off the topic of the original thread title. But rather than start a new thread, I suggest that you use the the "report" button and ask a moderator to change the title of this one to something more appropriate, like "some questions about scripting".
hi
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:
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?
"*" 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.
By the way, this thread is getting quite far off the topic of the original thread title. But rather than start a new thread, I suggest that you use the the "report" button and ask a moderator to change the title of this one to something more appropriate, like "some questions about scripting".
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
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
This should capture the part between the equal signs, and print out only that part of the line.
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.