Compare actual files with format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare actual files with format
# 1  
Old 10-16-2016
Compare actual files with format

Hi,

I have database table let say t_filenames which stores filenames and date_format in two columns.

e.g.

Code:
ABCD_TV_YYYYMMDD.txt                  YYYYMMDD
ABCD_MOUSE_YYYYMMDDHHMISS.txt           YYYYMMDDHHMISS

Actual files are available in a directory (say /tmp), actual files are with time/date details.
for e.g.
Code:
ABCD_TV_20160822.txt 
ABCD_MOUSE_20160814062822.txt

I would like to write a script to verify if all the files in the table are available over the directory. If exists create a dummy file if not just exist.

Could you please help me to solve this.

I tried to write a function which connects database and gets the filename and format. As a first step, the format would be replaced with ? marks and then used [[ ]] to verify if the file match. But not much success.



Thank you in advance.

Regards,
Pointers

Last edited by rbatte1; 10-17-2016 at 08:09 AM.. Reason: Added CODE tags for directory list and ICODE tags for important characters being replaced.
# 2  
Old 10-16-2016
Hello pointers1234,

I haven't have a real time scenario so didn't test this code, you could give it a try and let us know how it goes then.
Code:
cat script.ksh
### Here I am taking an example of sql db.
cat << EOF > sql_file.sql
select filenames from t_filenames;
EOF

sqlplus user_name/password@schema_name < sql_file.sql > output_file
#### Here we need to remove junk lines from file output_file which we will get once we connect to client. eg--> connected to: SQL*PLUS version etc.
which I can't predict until/unless you post output for above query with code tags here. So assuming we have removed those lines and have them into a file named output_file_names.
awk '{if($0 !~ /SQL*plus/ && $0 !~ /connected to/){print}}' output_file > output_file_names
while read line
do
	if [[ -f "/tmp/$line" ]]
	then
		echo "File named " $line " is present."
	else
		touch "/tmp/$line"
	fi
done < "output_file_names"

Though there could be more ways to perform this task, one could take this as a startup point.

Thanks,
R. Singh
# 3  
Old 10-20-2016
Sorry for being late to confirm.

Thank you, it helped me to solve the issue.

Regards,
Pointers
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to get output in mail in actual format?

I need top load memory and cpu uses in mail. I am getting mail, but output is coming in sentence format. can help me, how can I get in actual format. below is the command. echo `ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head`|mailx -r `hostname -s`@abc.com abc@abc.com (5 Replies)
Discussion started by: yash_message
5 Replies

2. Shell Programming and Scripting

How to compare two dates in a specific format ?

Hello, I am not able to find how to compare two dates in '%Y-%m-%d %H:%M:%S,%3N' format i have to two dates as below date1="2016-08-24 09:47:40,444" date2="2016-08-24 10:45:40,567" how to compare these two dates ? I have tried below without success if ; then echo 'yes'; fi ... (6 Replies)
Discussion started by: Ramneekgupta91
6 Replies

3. Shell Programming and Scripting

Perl CGI charts, actual plots and not image files

Does anyone know how to generate CGI charts which are not images , the one I am using generates image files e.g $mygraph3->set( 'x_labels_vertical' => 1 ); $mygraph3->set_legend_font(GD::gdMediumBoldFont); $mygraph3->set_legend('Test Plot'); my $myimage3 = $mygraph3->plot(\@data3)->png;... (4 Replies)
Discussion started by: priyophan
4 Replies

4. Shell Programming and Scripting

Need script for transferring bulk files from one format to text format

"Help Me" Need script for transferring bulk files from one format to text format in a unix server. Please suggest (2 Replies)
Discussion started by: Kranthi Kumar
2 Replies

5. Shell Programming and Scripting

How to compare the time in different format from a file?

15:09:50.350038 Reading A Data 15:09:50.371645 Reading B Data 15:10:55.655724 Initializing models 15:11:31.320920 Preparing Simulation 15:11:32.763217 Running Calculation 15:15:29.668882 Aggregating Results 15:15:29.950897 Persisting Results How could I make a matrix in H.M.S.MS... (7 Replies)
Discussion started by: manas_ranjan
7 Replies

6. Shell Programming and Scripting

Format & Compare two huge CSV files

I have two csv files having 90K records each & each row has around 50 columns.Lets say the file names are FILE1 and FILE2. I have to compare both the files and generate a new file that has rows from FILE2 if it differs. FILE1 ----- 2001,"John",25,19901130,21211.41,Unix Forum... (3 Replies)
Discussion started by: Sheel
3 Replies

7. Shell Programming and Scripting

awk compare column with date format

I have this code to compare columns 1 and 10 between file1 and file 2 and give me all records that match column 1 but dont match column 10 However column 10 is date format mm/dd/yy and awk cant read it and compare ...i tried awk < file1 -F~ '{print $10}' and it gave blank screen Is... (1 Reply)
Discussion started by: sigh2010
1 Replies

8. Shell Programming and Scripting

Shell script that will compare two config files and produce 2 outputs 1)actual config file 2)report

Hi I am new to shell scripting. There is a requirement to write a shell script to meet follwing needs.Prompt reply shall be highly appreciated. script that will compare two config files and produce 2 outputs - actual config file and a report indicating changes made. OS :Susi linux ver 10.3. ... (4 Replies)
Discussion started by: muraliinfy04
4 Replies

9. UNIX for Dummies Questions & Answers

compare two text files in a good format

I am writting a script where I have to Campare two text files. I have 3 text files named by s_list, s_list_new and dmg_file. where I have to compare s_list and s_list_new and whatever the unique values are in s_list I have to add that in the dmg_file. And the values they are only in s_list_new... (2 Replies)
Discussion started by: pareshan
2 Replies

10. UNIX for Dummies Questions & Answers

Searching list of entries in file for actual files in dir

Hi all, I have a file entries.txt that contains a number of entries all on seperate lines e.g. test1 test2 test3 test4 Then in a directory called /TestFiles I have a number of files that could contain the above text in the file name e.g. qwertytest1.csv qwertytest2.csv... (2 Replies)
Discussion started by: not4google
2 Replies
Login or Register to Ask a Question