posted
Google's being uncooperative, so for making a loop that terminates when the end of file is reached how would I do it or is counting the number of lines with grep the only way?
code:
add=$2 count=0 num=$(grep -c "" $1)
while $count <= $num do stuff count=$[count+add] done
posted
I thought you were going to complain about high gasoline prices and the evils of multi-national oil companies.
Posts: 1167 | Registered: Oct 2005
| IP: Logged |
posted
For that you'll need a counter in conjunction with while read line, or similar technique. I'm not familiar enough with bash to know what makes the most sense, but a counter isn't awful. You'll be freed from needing to know in advance how many lines there are (which is expensive), too.
Btw, it is almost certainly better to construct your script to take its input from stdin rather than an argument. And if you want to count lines, let me introduce you to the command wc.
What do you want the script to do, overall?
Posts: 15770 | Registered: Dec 2001
| IP: Logged |
Blayne Bradley
unregistered
posted
"create a bash script, which takes 2 parameters, a file name, an interger n; the script should output every nth line of the file to standard out. Print an errr message if the file does not exist."
To run a script witht he 2 passed parameters its ./scriptname param1 param2 ?
IP: Logged |
posted
Question if I do ./Script param1 param2 and check if the file exists how do I surpress bash's default standard ouput if a file/directory does not exist?
IP: Logged |
posted
Experimentation is the soul of programming.
Or something like that.
If you want to find, look to find. If you want to tar, look to tar. Ponder these well, and all will be revealed. It helps if you are drive a stick.
Posts: 15770 | Registered: Dec 2001
| IP: Logged |
quote:Originally posted by Artemisia Tridentata: I thought you were going to complain about high gasoline prices and the evils of multi-national oil companies.
I think you mean multi-national conglogmatates.
Posts: 21898 | Registered: Nov 2004
| IP: Logged |
posted
have you tried find? (I realize that its name is hardly indicative of what it does and all.)
Posts: 1621 | Registered: Oct 2001
| IP: Logged |
Blayne Bradley
unregistered
posted
quote:Originally posted by Bokonon: Blayne, don't be circumspect, and don't get people to do your homework.
-Bok
Don't be stupid, I'm not asking people to do my homework I'm asking for an explanation on how 2 commands work, which neither man nor the book seem to give any concrete examples, I have tried trial and error and it always recursively goes through every subdirectory when i just want the root.
IP: Logged |
posted
For about the 11th time, you'll never be even a passable programmer if you don't have the discipline to solve your own problems.
Posts: 5462 | Registered: Apr 2005
| IP: Logged |
Blayne Bradley
unregistered
posted
The most inane advice I had ever heard, this isn't a logic error, its just not understanding the manual pages or the linux book are saying on the command, they ay that tar cvf . makes a tarball and the n flag is needed to make it not do things recursively, I put it n tar, tar n, ncvf, cvfn, cvf -n, -n cvf its not working.
If no one at all asks for help when there's a problem then nothing is learned or accomplished.
IP: Logged |
posted
Indeed, my version of tar doesn't take -n.
Posts: 1810 | Registered: Jan 1999
| IP: Logged |
Blayne Bradley
unregistered
posted
quote:Originally posted by El JT de Spang: Not true at all. Stop being so lazy.
Now your just being an ignoramus, I would ask my teacher this question but I am not currently able to ask him the question, I have tried all of the above and it hasn't worked, so prove that I'm being lazy or don't post at all.
I am using Windows XP using Putty to access my schools Linux server, the version of tar is the GNU version.
Bash is the GNU born again Bourne Shell.
IP: Logged |
posted
Something like that. Not the subdirectories of root, though, everything in your home directory.
Posts: 15770 | Registered: Dec 2001
| IP: Logged |
Blayne Bradley
unregistered
posted
i usually refer to my home directory as root since its my personal linux server account.
IP: Logged |
posted
Don't; it is inaccurate and will result in misunderstandings when you discuss things with others.
Posts: 15770 | Registered: Dec 2001
| IP: Logged |
Blayne Bradley
unregistered
posted
hmm, I try to do a groupadd command, the man page says it exists but when i try to execute the command it doesnt work...
IP: Logged |
Any weird characters can be escaped as literals with a preceding backslash. You can also probably just put quotes around the file name you want to delete.
posted
First, computer science only peripherally relates to installing databases. It is a useful skill, but not one essential to being a decent, or even an expert, computer scientist.
Second, even if it is a good skill to learn, that does not mean it is a good idea to do on any account you have access to. A database server can, for instance, put considerable load on a system. If you do not secure it properly, your account could be compromised. There will be contention for ports, that could disrupt services on the server. Et cetera.
And you're supposed to already have access to a database, aren't you? Yeah, you must have been using it before. So if you want to install a database, install it on your own machine (preferably running linux, but MySQL installs okay on Windows).
Posts: 15770 | Registered: Dec 2001
| IP: Logged |
Blayne Bradley
unregistered
posted
Actually our CS program seems to cover all the bases, we will be isntalling MySQL and Linux in the next couple of weeks, I was hoping to do some of the leg work ahead of time.
IP: Logged |
posted
If you're going to be installing Linux, you'll be doing at least some of that stuff on a completely different box.
Of course, installing Linux (at least for the common variants) is as easy as installing Windows, nowadays, so I wonder what they're going to be teaching you.
And the proper way to install MySQL is (pretty much always) to use the command to install the MySQL package with your package manager.
Posts: 15770 | Registered: Dec 2001
| IP: Logged |
quote:Originally posted by fugu13: If you're going to be installing Linux, you'll be doing at least some of that stuff on a completely different box.
Of course, installing Linux (at least for the common variants) is as easy as installing Windows, nowadays, so I wonder what they're going to be teaching you.
Well, maybe they'll be using slackware and compiling the kernel. Regardless of the degree of difficulty, Comp Sci students ought to have some contact with linux/unix.
Posts: 433 | Registered: Feb 2005
| IP: Logged |
quote:Originally posted by Blayne Bradley: so I need to do some wierd piping of find to the tar command i think.
Watch out for the line length limit. Its really easy to go over it when piping from find to tar. There are several ways around it, but its really terrible when you untar that file to find out it didn't really work.
Personally, I like using -T.
Posts: 1621 | Registered: Oct 2001
| IP: Logged |
Blayne Bradley
unregistered
posted
ive decided to write the find results toa file and then run a do while loop going line by line tar balling it individually, tar seems to have by default cmpatibility with paths.
IP: Logged |