Solved

Comparing ASCII file to file list

Posted on 2004-09-22
10
157 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
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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Need Help INsttalling wget on Mavericks OS X 3 85
Question regarding Copy/Paste 16 87
List out all word 7 224
sameEnds challenge 3 107
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now