Solved

Comparing ASCII file to file list

Posted on 2004-09-22
10
159 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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ODBC Connection Logging, ADO.NET 6 64
ASCII Non-Printable characters/codes and their HTML equivalents 6 115
WinWaitActive parameters 12 31
either24  challenge 19 97
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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 video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

777 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