View Full Version : Newbie--Bash Script help
khufford
04-24-2004, 02:40 AM
linux newbie needs help
the problem is i have 2 directories /tmp1 and /tmp2
/tmp1 conatins 31 text files with the .txt extension named
file1.txt.....file31.txt
inside the text files are the lines
SMTPI-00001
SMTPI-00002
SMTP-00001
SMTP-00002
so on and so forth
/tmp2 contains 31 text files with the .log extension named
file1.log.......file31.log
in bash script how can i read each line of text in file1.txt and grep
each line to file1.log and loop through each file ie
file2.txt grep file2.log
file3.txt grep file3.log
and then pipe all the output to a single file
also note that some of the .txt text files have nothing in them so
nothing needs to be done on that particular file
skidooer
05-20-2004, 12:39 PM
for i in /tmp1/*.txt; do
for j in `cat $i`; do
grep $j `echo $i | sed -e 's!/tmp1/\(.*\).txt!/tmp2/\1.log!'`
done
done
iDxMan
05-20-2004, 08:29 PM
Hopefully you didn't just do someone's homework. ;)
skidooer
05-20-2004, 10:04 PM
Originally posted by iDxMan
Hopefully you didn't just do someone's homework. ;)
That doesn't bother me. If this is for homework, the best way to learn how to program is to look at example code anyway.
kryptech.net
05-20-2004, 10:19 PM
true, but he minght not be learning how to code, just getting on assignment a night from various forums around the internet.
iDxMan
05-21-2004, 12:18 AM
There's plenty of example code around. Working solutions are another story.. If this was an assignment, then most likely nothing (or very little) was learned.
...not that I really care. Just seemed homeworkish.
-r
khufford
05-21-2004, 01:41 PM
Thanks for all your help.
this was not homework assignment as some suggeted. I haven't done school home work in 25 years. I'm just a nebiw to Linux having to learn it as my company is looking to me to lead them into a Windows free environment in the future so thought I'd try to get a jump start on it by setting up a new email server. Next is a Linux/Samba PDC-BDC. Just so everyone knows I really do appreciate the help and no offense takin to the assignment portion. Everyone is entitled to thier opion be it right or wrong.
Whiteknight
07-05-2004, 01:17 AM
there are many instances on this forum of people creating an account, posting a single homework question that they are stumped on, and never coming back ever. I feel that this kind of practice is detrimental in several ways:
1) it detracts from the community. coderforums gets treated more as an answer database that caters to newbie programmers, and less like an intellegent programming forum.
2) it's dishonest. it's like cheating off the kid next to you on a test.
3) it's a waste of our time. we don't want to answer the same basic 40 questions over and over again.
i personally didnt think that this help request sounded like homework at all, and I'm gladd to see that you a) have more then 1 post, and b) explained that this wasnt an assignment, to appease the nay-sayers. if it hasnt bee said before, khufford: welcome to coder forums.
iDxMan
07-05-2004, 08:45 PM
Seemed homeworkish due to the comprehensive layout of the script requirements. It may not have sounded like HW to you, but many kiddies don't make any attempt to ask portions of the question. Rather they copy 100% of the requirements.
There's no need to appease anyone as I couldn't care less if they indeed cheated or not. Just adding my opinion with a winking smilie nonetheless.
...and yes, welcome khufford.
-r
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.