Solved

Comparing ASCII file to file list

Posted on 2004-09-22
10
161 Views
Last Modified: 2013-12-26
Good morning

I am really trying to get the hang of UNIX shell scripting so I am attempting some real weird tasks.  One such that I am having trouble with is as follows:

I am trying to take a list of function calls in an ASCII file and find out if there is a corresponding man page to it.  I know the parameters to find out if a man page exists, but my question is, "how do I iterate through the file 1 line at a time and make the comparison to the list given to me in standard output (or another file)?"

Thanks
0
Comment
Question by:joeltillman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 18

Assisted Solution

by:liddler
liddler earned 200 total points
ID: 12122215
something like:

#!/bin/ksh
for line in `cat ascii_file`
do
    for word in `cat word_list`
    do
        if [[ -n `grep ${word} ${line}` ]]
        then
        manual page stuff
        fi
    done
done


I haven't tested it (for syntax errors), but it should help you get started
0
 
LVL 6

Assisted Solution

by:Talmash
Talmash earned 100 total points
ID: 12122228
hi ,

this command :
foreach word (`cat file`)
echo $word
end

will seperate the file , line by line to seperated words .

we may relay on the fact that all the shell commands are seperated with " " after .

but , sometimes scripts hold commands that comes exactly after ">" or "|" , so you should use some parser (perl , few regex should do the job) .

in case the script u r handling wrote by a "clear" writter , you will have no problem (no commands attached to special signs like | & > etc...)

any problem , I am here .

shana tova ,
tal
0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 12122252
Hi,

The following goes through your list, one word at a time, and searches the entire sourcefile... not exactly what you wanted, but close...

#!/bin/bash
search_file=$1
source_file=$2
# note, takes all space seperated words, not whole lines... slightly different code for whole lines....
for word in $(cat $search_file)
do
    grep $word source_file
done
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:joeltillman
ID: 12122502
When I attempt to use "for" and "do" I get Command not found and word returns illegal variable.  Once again, I apologize for not knowing about all of this.
0
 

Author Comment

by:joeltillman
ID: 12122508
Sorry, "word" return undefined variable
0
 
LVL 18

Expert Comment

by:liddler
ID: 12122559
Have you got a shell line (#!/bin/ksh)
as the first line of your script?
you need to be sure to differentiate between back single tick ` and forward single quote '

Is the script executeable
chmod a+x script_name


Post you full script here if you are still stuck
0
 

Author Comment

by:joeltillman
ID: 12123870
That worked kind of, but not fully.  I should probably make my question more specific.

I'd like to take my $word variable and find out if any man pages match the variable in some way or another.  for example, if i have func_1("PARAM1",  "PARAM2")

iI would like to find out if any man pages exist for the func_1 part.
0
 
LVL 18

Accepted Solution

by:
liddler earned 200 total points
ID: 12125141
ok so when it matches, do something like
func=`cut $line -d'(' -f1`
to return $func which will be the line up to the first (
then
man $func
0
 

Author Comment

by:joeltillman
ID: 12126025
Still no luck.  Here is my script.  May make it easier to look at

#Utilize grep to find lines containing the pattern "name(function)"
grep "[a-z]*_[a-z]\(.*\)" CPROGRAMS.c > tempfile
#Iterate through functionlist file and check for man pages
for word in $(cat tempfile)
do
      func=`cut $word -d'(' -f1`
      mandoc = `man -l $func`
      grep func $mandoc > matched      
done
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 100 total points
ID: 12127838
Try this:

#!/bin/sh
for func in `awk -F'(' '/^.*\(.*\)/ {print $1}' CPROGRAMS.c`
do
  man -l $func 2>/dev/null >>matched
done
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
iSeries DB2 Query 2 98
Change owner from userA to server Local Administrators 7 71
only14 challenge 19 84
EvenOdd challenge 10 148
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question