[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

Comparing ASCII file to file list

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
joeltillman
Asked:
joeltillman
4 Solutions
 
liddlerCommented:
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
 
TalmashCommented:
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
 
cjjcliffordCommented:
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
Technology Partners: 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!

 
joeltillmanAuthor Commented:
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
 
joeltillmanAuthor Commented:
Sorry, "word" return undefined variable
0
 
liddlerCommented:
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
 
joeltillmanAuthor Commented:
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
 
liddlerCommented:
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
 
joeltillmanAuthor Commented:
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
 
TintinCommented:
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now