ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Hi Guys, I am sysadmin and I know a lot of stuffs but when comes to programming and shell script I get stuck.
I need to write a script that will compare two files in the following way.
file1 = about 1800 lines
file2 = about 700 lines.
I need to check if all lines in file2 is inside of file1
how can I do that ? I really appreciate your help. Sorry if this is too beginner.
...or you can go to Google, and look up one of the THOUSANDS of easily-found bash scripting tutorials. Read the "Question Guidelines" link in my posting signature.
Since you've been programming for years, you should know that there are many ways to do this, depending on the lines in question, of which you post NO samples. Further, you don't say what language you want to use. You may be able to slurp the whole smaller file into an array in Perl and grep through the other file quickly...or can read one line at a time, and look for it in the other file, and set a flag/exit if you don't find it.
Many ways to do it....so show us what YOU have thought of/done/tried and we can try to help.
My Friend, I don't know you, but I don't think this is a good way to answer my questions. I do have lots of experience in Linux but NOT in programming. I know how to find strings in a file etc but I am NOT good with programming logic, that's why I posted a question here.
Beside, looks at the date I posted the questions. I haven't done a shell script since 2011. I wasn't good, and now I forgot a lot of things. You CANNOT just assume that because I posted those questions that I am a programmer and I know how to do it.
I HAVE POSTED THIS QUESTIONS BECAUSE I DON'T KNOW HOW TO DO IT, AND BELIEVE ME I HAVE GOOGLED FOR IT A LOT.
If you don't want it's fine, but don't stay in the way. YOu don't know my life enough to say anything.
...or you can go to Google, and look up one of the THOUSANDS of easily-found bash scripting tutorials. Read the "Question Guidelines" link in my posting signature.
Since you've been programming for years, you should know that there are many ways to do this, depending on the lines in question, of which you post NO samples. Further, you don't say what language you want to use. You may be able to slurp the whole smaller file into an array in Perl and grep through the other file quickly...or can read one line at a time, and look for it in the other file, and set a flag/exit if you don't find it.
Many ways to do it....so show us what YOU have thought of/done/tried and we can try to help.
My Friend, I don't know you, but I don't think this is a good way to answer my questions. I do have lots of experience in Linux but NOT in programming.
First, I'm NOT your friend. And yet you've been posting programming questions for YEARS now.
Quote:
I know how to find strings in a file etc but I am NOT good with programming logic, that's why I posted a question here.
Really?? Despite posting NUMEROUS programming questions WITH CODE???
Quote:
Beside, looks at the date I posted the questions. I haven't done a shell script since 2011. I wasn't good, and now I forgot a lot of things. You CANNOT just assume that because I posted those questions that I am a programmer and I know how to do it.
No, but since:
You have been here for SEVEN YEARS
You have asked NUMEROUS programming questions, and provided code
You have AMPLE resources to be able to write a bash script on your own
You have OBVIOUSLY not tried to look up MANY tutorials and examples you can find on Google for bash scripting
You have OBVIOUSLY not tried to look this up on LQ either, since this has been asked (and answered) MANY times here
You DID NOT say which language you wanted to do this in
..and most importantly:
YOU SHOWED NO EFFORT OF YOUR OWN
Quote:
I HAVE POSTED THIS QUESTIONS BECAUSE I DON'T KNOW HOW TO DO IT, AND BELIEVE ME I HAVE GOOGLED FOR IT A LOT.
No, I don't believe you...since there are THOUSANDS of hits for this.
Quote:
If you don't want it's fine, but don't stay in the way. YOu don't know my life enough to say anything.
I know you're trying to get someone else to do this for you...and I'm happy to help you, but YOU, PERSONALLY have to show some effort of your own.
yet, I DO NOT KNOW HOW TO DO THIS SHELL SCRIPT. This used to be a very good forum but unfortunatlly people like you are spoiling it.
I won't argue with you any more. I will find a another forum for help.
AGAIN, I DO NOT KNOW HOW TO SOLVE THIS. Yet if I knew I would already have done it myself and wasn't here in this forum loosing my time arguing with you.
AGAIN, you do not know about my life, I started to work with different things not related to computer and now I am back to this kind of job, that's whay I don't remember almost anything, because when you don't practice your forgot stuffs. And I do run into people like you. That's said.
AGAIN, YOU DO NOT HAVE ENOUGH INFORMATION ABOUT ME TO SAY THAT.
I wanted to do with shell script, of course. And I already have google for it a lot.
You're far more generous than I would have been, given the OP's posting history and apparent lack of effort.
I wondered the EXACT same thing.
In the time it takes me to whip out a for i loop, I may as well have done the script for him.
I'd rather post concepts/techniques
I'd rather lead them to water and most days I agree with the things you write/say.
I must have 1000 links bookmarked for things I know nothing about
I bookmark 'em because I see the value in code even when I am not using the code that I value.
As for google, it practically answers the question(s) as you type them in, so I have to wonder what people "do" at google exactly.
There was this guy once, he posted the Year's Most Horrific Crime Stats for Chicago (way back in the early days, circa ~2000) and he
then hacked the Chicago PD website and overlayed the Crime Stats on the PD's webpage.
The news reported "Chicago PD is looking him, so is Google".
When they found him, they asked how he did it.
He replied I asked google how.
Yes I did created another user because I DO NOT KNOW HOW TO SOLVE THIS. for god sake
Quote:
Originally Posted by gabrielpasv
I don't know what else to do but laugh at you.
yet, I DO NOT KNOW HOW TO DO THIS SHELL SCRIPT. This used to be a very good forum but unfortunatlly people like you are spoiling it.
I won't argue with you any more. I will find a another forum for help.
AGAIN, I DO NOT KNOW HOW TO SOLVE THIS. Yet if I knew I would already have done it myself and wasn't here in this forum loosing my time arguing with you.
AGAIN, you do not know about my life, I started to work with different things not related to computer and now I am back to this kind of job, that's whay I don't remember almost anything, because when you don't practice your forgot stuffs. And I do run into people like you. That's said.
AGAIN, YOU DO NOT HAVE ENOUGH INFORMATION ABOUT ME TO SAY THAT.
I wanted to do with shell script, of course. And I already have google for it a lot.
I don't know what else to do but laugh at you.
yet, I DO NOT KNOW HOW TO DO THIS SHELL SCRIPT. This used to be a very good forum but unfortunatlly people like you are spoiling it.
Just like people who ignore the forum rules, and create second user ID's? And again, we will HELP you, so show what effort you have put forth. Asking for things without showing any effort is nothing but asking for a handout. You say you've been a systems administrator for SEVEN YEARS, and have posted numerous programming questions...and you actually expect us to believe that you have NO IDEA how to BEGIN to write a simple shell script???
Quote:
I won't argue with you any more. I will find a another forum for help.
Thank you.
Quote:
AGAIN, I DO NOT KNOW HOW TO SOLVE THIS. Yet if I knew I would already have done it myself and wasn't here in this forum loosing my time arguing with you.
Great...no one is arguing with you. We're asking you to show what effort you have put forth. You have not.
Quote:
AGAIN, you do not know about my life, I started to work with different things not related to computer and now I am back to this kind of job, that's whay I don't remember almost anything, because when you don't practice your forgot stuffs. And I do run into people like you. That's said. AGAIN, YOU DO NOT HAVE ENOUGH INFORMATION ABOUT ME TO SAY THAT.
I only know what you post. And you've posted for seven years, and posted about programming, and have (going on) 200 posts. You should be WELL aware of the forum guidelines (read "Question Guidelines" and "How to ask a smart question" links), about doing basic research first.
Quote:
I wanted to do with shell script, of course.
And how are we supposed to know "of course"? when you don't SAY what you're after? You can do this with a dozen different languages, including (as pointed out) the diff command.
Quote:
And I already have google for it a lot.
Sorry, just don't believe you. Habitual handed you numerous links. Putting "how to find out if all lines in one file are in another in linux" gives 89 MILLION results.
And you honestly expect us to believe you "google for it a lot"????
In the time it takes me to whip out a for i loop, I may as well have done the script for him.
I'd rather post concepts/techniques
I'd rather lead them to water and most days I agree with the things you write/say.
Exactly...but after seven years, how much more leading can one do? And claiming ignorance after posting programming questions is even worse.
Quote:
I must have 1000 links bookmarked for things I know nothing about I bookmark 'em because I see the value in code even when I am not using the code that I value.
ABSOLUTELY...I have a similar list. Someone here posted one the other day that was great, and I have it saved off too.
Quote:
As for google, it practically answers the question(s) as you type them in, so I have to wonder what people "do" at google exactly.
There was this guy once, he posted the Year's Most Horrific Crime Stats for Chicago (way back in the early days, circa ~2000) and he
then hacked the Chicago PD website and overlayed the Crime Stats on the PD's webpage.
The news reported "Chicago PD is looking him, so is Google". When they found him, they asked how he did it. He replied I asked google how. I am motivated by this experience, see new sig.
Yep...that's how I learned almost all the languages I know. I sure didn't ask for handouts, but started looking for ways to do what I wanted, trying them, and learning from those mistakes.
I just don't see how anyone, in 2016, can show no effort of their own, with the amount of information/samples/examples that are literally at their fingertips.
As I've said many times in other threads, I'll gladly help anyone, but I refuse to give handouts. Posting "hey, I'm trying to do xxxx, with these commands, and I'm just not getting the results I think I should, based on yyyy from the man pages. I'm missing something, can anyone help?" is one thing. Someone who has years of experience, and claims to "know lots', and has asked programming questions before, and asks something VERY common with no visible effort? Thanks, but no...
Yes I did created another user because I DO NOT KNOW HOW TO SOLVE THIS. for god sake
Thanks for ignoring the LQ Rules. Stop complaining, and start doing some work, and show some effort.
There are hundreds (if not thousands) of links on this very site that deal with this question. 89 million hits on Google. Not sure how much more guidance/hints/suggestions/samples you need, before you can start to do something on your own.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.