LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 04-05-2012, 07:13 AM   #16
ofer4
Member
 
Registered: Apr 2012
Posts: 100

Original Poster
Rep: Reputation: Disabled

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

Last edited by ofer4; 04-05-2012 at 09:55 AM.
 
Old 04-05-2012, 09:44 AM   #17
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by ofer4 View Post
...
tests\input.in
...
"./testInOut: line 5: tests/input.in.in: No such file or directory"
...
"test/input.in"
Please post your script or the first 5 lines if it is long.

Is the directory tests/ or test/?
 
Old 04-05-2012, 09:56 AM   #18
ofer4
Member
 
Registered: Apr 2012
Posts: 100

Original Poster
Rep: Reputation: Disabled
thanks for the advice

i edit my post (i mean tests directory)

please, soeone can help me?
 
Old 04-05-2012, 10:24 AM   #19
ofer4
Member
 
Registered: Apr 2012
Posts: 100

Original Poster
Rep: Reputation: Disabled
i have one more question:

i wrote this code:

Code:
#!/bin/bash

cat "1.memory.log" | grep ==*==
i want to display all the names which start with "==" and end with "=="

however my script doesnt work

any ideas?
 
Old 04-05-2012, 11:35 AM   #20
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
"*" 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
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".
 
Old 04-05-2012, 11:47 AM   #21
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by ofer4 View Post
please, soeone can help me?
Please post your script or the first 5 lines if it is long.
 
Old 04-05-2012, 12:05 PM   #22
uhelp
Member
 
Registered: Nov 2011
Location: Germany, Bavaria, Nueremberg area
Distribution: openSUSE, Debian, LFS
Posts: 205

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

Last edited by uhelp; 04-05-2012 at 12:08 PM.
 
Old 04-05-2012, 01:28 PM   #23
ofer4
Member
 
Registered: Apr 2012
Posts: 100

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by David the H. View Post
"*" 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
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?

thanks alot
 
Old 04-05-2012, 09:53 PM   #24
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by ofer4 View Post
and please someone post a solution to my second problem...i didnt find any solution for it
Please post the script that is having the problem
 
Old 04-06-2012, 05:08 PM   #25
ofer4
Member
 
Registered: Apr 2012
Posts: 100

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by David the H. View Post
"*" 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
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
 
Old 04-07-2012, 06:21 AM   #26
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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.
 
Old 04-07-2012, 04:38 PM   #27
ofer4
Member
 
Registered: Apr 2012
Posts: 100

Original Poster
Rep: Reputation: Disabled
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
 
Old 04-08-2012, 09:55 AM   #28
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

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

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
 
  


Reply



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
Newbie questions with shell scripting, tronky Programming 4 03-21-2011 09:54 AM
shell scripting questions tlarkin Programming 8 05-11-2007 03:49 PM
Shell Scripting Questions blaoulis Programming 5 07-12-2006 07:21 PM
Shell Scripting Exit(s) liguorir Linux - Software 3 04-21-2004 10:59 AM
Two Linux shell scripting questions thepryme Programming 5 10-23-2003 07:01 AM

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

All times are GMT -5. The time now is 01:28 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