[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Comparing ASCII file to file list

Posted on 2004-09-22
10
Medium Priority
?
170 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 600 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 300 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
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 

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 600 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 300 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

656 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