need a shell script to extract the files from source file and check whether those files existonserve

Hi,
I am new to shell scripting.Please help me on this.I am using solaris 10 OS and shell i am using is

# echo $0
-sh

My requirement is i have source file say makefile.I need to extract files with extensions (.c |.cxx |.h |.hxx |.sc) from the makefile.after doing so i need to check whether those files exist on the solaris server and if so what is the location they are present.could somebody help on this?

---------- Post updated at 07:43 AM ---------- Previous update was at 06:53 AM ----------

i have used folllowin command to extract files from the source file.

egrep '(.c |.cxx |.h |.hxx |.sc )' makefile | grep -v '#'>srclst

i am able to direct the out put to srclst file.Now searching command to find the file from teh srclist file and need to check where that file is located on the server

for f in `grep -v '^#' Makefile | grep -Eo '[^[:space:]]*\.(c|cxx|h|hxx|sc)([[:space:]]|$)' | sort -u`; do find . -name "$f"; done

Grep uses regular expressions and . has a special meaning, it means any character. To look for a . you need to escape it : \.

hi,
Thanks for u r reply.It's giving trouble with grep -E option.
output of the command:

do find . -name "$f";
done> >
grep: illegal option -- E
grep: illegal option -- o
Usage: grep -hblcnsviw pattern file . . 

I have removed -E and ran the script with grep -li.not sure what is the impact of chnanging it.
i will explain the requirement in a very clear manner.
1)I have source file named makefile.i am grepping some extention files like .c,.cxx etc from it and moving the output to a filename srctxt.
2)then i need to check whatever files present in srctxt are present in server.say if i have file.c in srctxt file i need to check the file exist on server
find / - name file.c -print.
3)ultimate goal is if i whatever file present in srctxt file say file.c if not present in solaris serve i need to findout that files and need to get that from external vendor.so need to run a loop for finding the file and if i didnot find the file then need send a error like file doesnot exist.

once again thanks verymuch for u r reply.

On Solaris use /usr/xpg4/bin/grep instead of grep.

thanks for the reply.i have modified the grep to /usr/xpg4/bin/grep and option E is working with it.But after running it scritpt not coming out.
output after running script:

# for f in `grep -v '^#' makefile | /usr/xpg4/bin/grep -E '[^[:space:]]*\.(c|cxx|h|hxx|sc)([[:space:]]|$)' | sort -u`;
>  do find . -name "$f";
> done

what can be done now?

Hi,

can you post sample input of makefile( contains file name) ?
it contains only file name or information along with file name.

egrep -e '\.(c|cxx|h|hxx|sc)$' makefile

Here i am assuming that make file contains only file name.

Cheers,
Ranga:)

sample informatio in the make file:

src/vsxa0142.cxx src/vsxf0229.sc  src/vsxf0323.sc  src/vsxf0865.sc
#       src/vsxa0168.cxx src/vsxf0231.sc  src/vsxf0324.sc  src/vsxf0866.sc
#       src/vsxa0176.cxx src/vsxf0232.sc  src/vsxf0325.sc  src/vsxf0867.sc
#       src/vsxa0180.cxx src/vsxf0233.sc  src/vsxf0332.sc  src/vsxf0868.sc
#       src/vsxa0221.cxx src/vsxf0234.sc  src/vsxf0362.sc  src/vsxf0932.sc
#       src/vsxg0001.cxx src/vsxf0264.sc  src/vsxf0364.sc  src/inbuf.C
#       src/vsxg0004.cxx src/vsxf0265.sc  src/vsxf0368.sc  src/outbuf.C
#       src/vsxg0005.cxx src/vsxf0266.sc  src/vsxf0369.sc  src/printbuf.C
 src/vsxs0016.C   src/vsxa0172.cxx src/vsxg0153.cxx src/vsxa0076.cxx

thanks for the reply.this is the information in the make file.ultimate goal is all the files names which are having .c|cxx|h etc in the make file should also present in the server.if not present need to get that file names from the external vendors.Problem is there are thousands of files with extensions.need to search the files in server and if they present in server ok or else need to note down the file names which are missing.
hope i have provided requested details

Hi Murali,

Try this one,

#! /usr/bin/bash
makefile="File"
filenotfoundlog="filenotfoundlog.log"
filefoundlog="filefoundlog.log"
for files in `awk '$0 !~ /^#/{split($0,a," ");for(i=1;i<=NF;i++){if ( a ~ /\.(c|cxx|h|hxx|sc)$/ ){print a;}}}' $makefile`
do
        if [ -f "$files" ]; then
                echo "$files" >>$filefoundlog
        else
                echo "$files" >>$filenotfoundlog
        fi
done

Just assign makefile name and output logs name based on you wish.
This script will give two log file.

  1. what are the file not found in the system - filenotfoundlog.
  2. what are the files found in the system - filefoundlog.

I have some assumtion,

  1. make file is space separated file and have the full path in make file.
src/vsxs0016.C src/vsxa0172.cxx src/vsxg0153.cxx src/vsxa0076.cxx

In the above line, i assume that

src

is a base name of that file.

Cheers,
Ranga:)

Hi thanks a lot for the reply.I guess it is giving trouble at awk part.After execution of the script it throwing an error.
Error :
awk: can't open File
#

Just change the makefile name that is your input file right ?

makefile="File" 

Cheers,
Ranga:)

1 Like

Superb.Thanks for the reply.It is working ..cheers

wc!!! Cheers :slight_smile:

r u working in chennai?may i know where are u working?