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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need a shell script to extract the files from source file and check whether those files existonserve
# 1  
Old 02-21-2012
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
Code:
# 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.
Code:
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

Last edited by Franklin52; 02-22-2012 at 06:00 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 02-21-2012
Code:
for f in `grep -v '^#' Makefile | grep -Eo '[^[:space:]]*\.(c|cxx|h|hxx|sc)([[:space:]]|$)' | sort -u`; do find . -name "$f"; done

# 3  
Old 02-21-2012
Grep uses regular expressions and . has a special meaning, it means any character. To look for a . you need to escape it : \.
# 4  
Old 02-21-2012
hi,
Thanks for u r reply.It's giving trouble with grep -E option.
output of the command:
Code:
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.

Last edited by Franklin52; 02-22-2012 at 06:00 AM.. Reason: Please use code tags for code and data samples, thank you
# 5  
Old 02-21-2012
On Solaris use /usr/xpg4/bin/grep instead of grep.
# 6  
Old 02-22-2012
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:
Code:
# 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?

Last edited by Franklin52; 02-22-2012 at 06:01 AM.. Reason: Code tags
# 7  
Old 02-22-2012
find

Hi,

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

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

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

Cheers,
RangaSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to check a file and delete old files

Hello, I needed help with a shell script where in it checks if a file exists under a directory and also checks the age of the file and delete it if it is older than 3 weeks. thanks (10 Replies)
Discussion started by: hasn318
10 Replies

2. Shell Programming and Scripting

Shell/perl script to check for files

Hi, I am trying to write a script for following scenario: I have a list of countries from where I receive files...eg. (Indonesia, Thailand, Australia...etc) For each country, I have a list of files that they send. IND -- a,b,c TH -- p,q,r AU -- x,y,z The path for these files could... (2 Replies)
Discussion started by: neil.k
2 Replies

3. Shell Programming and Scripting

Standardization of input source data files using shell script

Hi there, I'm a newbie in unix and am fishing for options related to how raw input data files are handled. The scenario, as I'm sure y'all must be very familiar with, is this : we receive upwards of 50 data files in ASCII format from various source systems - now each file has its own structure... (3 Replies)
Discussion started by: Prat Khos
3 Replies

4. Shell Programming and Scripting

How to check whether directory has files in it or not in shell script?

hi, I am having script in which i want to check if directory has any file in it or not. If directory contains a single or more files then and only then it should proceed to further operations... P.S.: Directory might have thousand number of files. so there might be chance of getting error... (4 Replies)
Discussion started by: VSom007
4 Replies

5. Shell Programming and Scripting

Shell script to check files if exist else touch the file

Hi All, Thanks in Advance I wrote the following code if then echo "version is 1.1" for i in "subscriber promplan mapping dedicatedaccount faflistSub faflistAcc accumulator pam_account" do FILE="SDP_DUMP_$i.csv" echo "$FILE" ... (5 Replies)
Discussion started by: aealexanderraj
5 Replies

6. Shell Programming and Scripting

shell script to take input from a text file and perform check on each servers and copy files

HI all, I want to script where all the server names will be in a text file like server1 server2 server3 . and the script should take servernames from a text file and perform copy of files if the files are not present on those servers.after which it should take next servername till the end of... (0 Replies)
Discussion started by: joseph.dmello
0 Replies

7. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies

8. Shell Programming and Scripting

Shell script to check the files hourly and purge

I'm new to shell scripting... i have been given a task.. can any one help in this regard.... 1) Check hourly for files in <destination-path><destination-file-template><destination-file-suffix> for files older than <destination-file-retention> days and purge. It should then check... (1 Reply)
Discussion started by: satishpabba
1 Replies

9. Shell Programming and Scripting

HOW TO CHECK ONLY .C FILES EXISTS OR NOT IN A FOLDER using IF in C shell script?

Hi friends.. I hav a problem.... I dont know how to check .c files exists r not in a folder using IF in C shell script actually i tried like this if(=~ *.c) even though some .c files or there in the current folder..it is not entering int o the if control statement...... (17 Replies)
Discussion started by: p.hemadrireddy
17 Replies

10. Shell Programming and Scripting

Shell script to transfer the files from source to target server.

I need to write a shell script to transfer the files every hour from source - target server. The cron job should be running every hour and shouldn't copy already copied files to the remote server ? I was able to write intial script but not able to get the logic for (in the next run it should... (12 Replies)
Discussion started by: radhirk
12 Replies
Login or Register to Ask a Question