Computing.Net > Forums > Unix > shell script help please

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

shell script help please

Reply to Message Icon

Original Message
Name: Gordy
Date: April 6, 2003 at 22:56:17 Pacific
Subject: shell script help please
OS: Unix
CPU/Ram: na
Comment:

Hi everyone...

I posted about this before, but I'm still having some problems. My script below reads (or trys to at least) read in lines of a file and then see if some part of the line matches the input from the user, $1..

Here's a sample text file that I have been using with some random images... if I search for "cookie", the image for cookie is displayed 8 times... I want it to display once.. and if I search for book.. i want picture 7 and 1 to show up..

Any help would be REALLY appreciated.. thanks.

glg2296/art/images/picture1.jpg:author:cookie
glg2296/art/images/picture2.jpg:author:chair
glg2296/art/images/picture3.jpg:author:apple
glg2296/art/images/picture4.jpg:author:grapes
glg2296/art/images/picture5.jpg:author:car
glg2296/art/images/picture6.jpg:author:monkey
glg2296/art/images/picture7.jpg:author:book
glg2296/art/images/picture1.jpg:author:book

#!/bin/sh
echo "Content-type: text/html"
echo


counter=`wc -l "


for (( i=0; i"

#cat line.txt

#grep "$1" database.txt >temp.txt

#grep "$1" $line > results.txt

grep $1 database.txt> temp.txt

#cat temp.txt

p=`awk -F: '{print $1}' temp.txt | sed 's#//##'`
#p=`awk -F: '{print $1}' results.txt | sed 's#//##'`

#cat temp.txt
echo ""
echo ""


#rm temp.txt


Report Offensive Message For Removal


Response Number 1
Name: nails
Date: April 7, 2003 at 07:26:21 Pacific
Reply: (edit)

Gordy:

A common technique is to use the uniq command:

# untested
p=`awk -F: '{print $1}' temp.txt |uniq| sed 's#//##'`

Regards,

Nails


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 2 Days.
Discuss in The Lounge
Poll History




Data Recovery Software