Sponsored Content
Top Forums Shell Programming and Scripting how to search string and number in one file and check in the other file Post 302133352 by aigles on Thursday 23rd of August 2007 04:55:16 AM
Old 08-23-2007
Quote:
Originally Posted by knshree in private message
Hi,
Thanks for the reply.
I am new to scripting.
I have the file1.log with below contents:

fileset 999 primary-ilist inode 37020 has invalid dotdot (426094)
fileset 999 primary-ilist inode 115016 dup block
fileset 999 primary-ilist inode 116614 dup block
fileset 999 primary-ilist inode 116616 dup block

file2.log has below contents

/export/jumpstart/solaris9_image/Solaris_9/Product/SUNWimagick/archive:
total 3926
81691 drwxr-xr-x 2 root staff 96 Jun 29 2004 .
81690 drwxrwxr-x 5 root staff 1024 Jun 29 2004 ..
116610 -rw-r--r-- 1 root staff 2008248 Apr 27 2004 none.bz2

/export/jumpstart/solaris9_image/Solaris_9/Product/SUNWimagick/install:
total 18
116611 drwxr-xr-x 2 root staff 96 Jun 29 2004 .
81690 drwxrwxr-x 5 root staff 1024 Jun 29 2004 ..
116612 -rw-r--r-- 1 root staff 2116 Apr 21 2004 copyright
116613 -rw-r--r-- 1 root staff 1300 Apr 21 2004 depend
116614 -rw-r--r-- 1 root staff 2245 Apr 27 2004 i.none

/export/jumpstart/solaris9_image/Solaris_9/Product/SUNWimagick/reloc:
total 2
116617 drwxr-xr-x 3 root staff 96 Jun 29 2004 .
81690 drwxrwxr-x 5 root staff 1024 Jun 29 2004 ..
116618 drwxr-xr-x 3 root staff 96 Jun 29 2004 usr

below are the steps and needs scripting

I have to read 30720 in file1
search 30720 in file2
print 'Not exist'

I have to read next 115016 in file1
search 115016 in file2
print 'not exist'

I have to read next 116366 in file1
search 116366 in file2
print 'not exist'

..........

I have to read 116614 in file1
search 116614 in file2
if it exists (print the following)
print '/export/jumpstart/solaris9_image/Solaris_9/Product/SUNWimagick/install'

please help me how to do in a scripting.

thanks
Try and adapt the following script :
Code:
awk '

# First file
NR==FNR {
   if (/:$/)
      Paths[++PathsCount] = substr($0, 1, length-1);
   else if (NF==10)
      Inodes[$1] = PathsCount;
   next;
}

# Other files

NF>1 {
   if ($5 in Inodes)
      path = Paths[Inodes[$5]]
   else
      path = "Not exist";
   print $0,"->",path;
}

' file2.log file1.log

With your sample datas posted, the result is :
Code:
fileset 999 primary-ilist inode 37020 has invalid dotdot (426094) -> Not exist
fileset 999 primary-ilist inode 115016 dup block -> Not exist
fileset 999 primary-ilist inode 116614 dup block -> /export/jumpstart/solaris9_image/Solaris_9/Product/SUNWimagick/install
fileset 999 primary-ilist inode 116616 dup block -> Not exist

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

count the number of files which have a search string, but counting the file only once

I need to count the number of files which have a search string, but counting the file only once if search string is found. eg: File1: Please note that there are 2 occurances of "aaa" aaa bbb ccc aaa File2: Please note that there are 3 occurances of "aaa" aaa bbb ccc... (1 Reply)
Discussion started by: sudheshnaiyer
1 Replies

2. UNIX for Dummies Questions & Answers

how can search a String in one text file and replace the whole line in another file

i am very new to UNIX plz help me in this scenario i have two text files as below file1.txt name=Rajakumar. Discipline=Electronics and communication. Designation=software Engineer. file2.txt name=Kannan. Discipline=Mechanical. Designation=CADD Design Engineer. ... (6 Replies)
Discussion started by: kkraja
6 Replies

3. Shell Programming and Scripting

search a string in a particular column of file and return the line number of the line

Hi All, Can you please guide me to search a string in a particular column of file and return the line number of the line where it was found using awk. As an example : abc.txt 7000,john,2,1,0,1,6 7001,elen,2,2,0,1,7 7002,sami,2,3,0,1,6 7003,mike,1,4,0,2,1 8001,nike,1,5,0,1,8... (3 Replies)
Discussion started by: arunshankar.c
3 Replies

4. Shell Programming and Scripting

How to search number of occurrences of a particular string in a file through vi editor?

i have one file, i am doing 'vi Filename' now i want to search for particular string and i want to know how many times that string occurs in whole file (5 Replies)
Discussion started by: sheelsadan
5 Replies

5. Shell Programming and Scripting

Help in printing n number of lines if a search string matches in a file

Hi I have below script which is used to grep specific errors and if error string matches send an email alert. Script is working fine , however , i wish to print next 10 lines of the string match to get the details of error in the email alert Current code:- #!/bin/bash tail -Fn0 --retry... (2 Replies)
Discussion started by: neha0785
2 Replies

6. Shell Programming and Scripting

Need to search a particular String form a file a write to another file using perl script

I have file which contains a huge amount of data. I need to search the pattern Message id. When that pattern is matched I need to get abcdeff0-1g6g-91g3-1z2z-2mm605m90000 to another file. Kindly provide your input. File is like below Jan 11 04:05:10 linux100 |NOTICE... (2 Replies)
Discussion started by: Raysf
2 Replies

7. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

8. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

9. Shell Programming and Scripting

Search a string in a file which is also present in another file in UNIX

Hi there, I am new to Unix and had below requirement to finish my task. I have file1.dat which has data as shown below. case1.txt case2.txt case3.txt case4.txt file1.dat has only file names I have folder which has above files mentioned in file1.dat ./all_files case1.txt... (6 Replies)
Discussion started by: raj028
6 Replies

10. UNIX for Beginners Questions & Answers

Search a string and display its location on the entire string and make a text file

I want to search a small string in a large string and find the locations of the string. For this I used grep "string" -ob <file name where the large string is stored>. Now this gives me the locations of that string. Now how do I store these locations in a text file. Please use CODE tags as... (7 Replies)
Discussion started by: ANKIT ROY
7 Replies
h5diff(1)						      General Commands Manual							 h5diff(1)

NAME
h5diff - Compares two HDF5 files and reports the differences. SYNOPSIS
h5diff file1 file2 [OPTIONS] [object1 [object2 ] ] DESCRIPTION
h5diff is a command line tool that compares two HDF5 files, file1 and file2, and reports the differences between them. Optionally, h5diff will compare two objects within these files. If only one object, object1, is specified, h5diff will compare object1 in file1 with object1 in file2. In two objects, object1 and object2, are specified, h5diff will compare object1 in file1 with object2 in file2. These objects must be HDF5 datasets. object1 and object2 must be expressed as absolute paths from the respective file's root group. Additional information, with several sample cases, can be found in the document H5diff Examples. OPTIONS
file1 file2 The HDF5 files to be compared. -h Print all differences. -r Print only the names of objects that differ; do not print the differences. These objects may be HDF5 datasets, groups, or named datatypes. -n count Print difference up to count differences, then stop. count must be a positive integer. -d delta Print only differences that are greater than the limit delta. delta must be a positive number. The comparison criterion is whether the absolute value of the difference of two corresponding values is greater than delta (e.g., |a-b| > delta, where a is a value in file1 and b is a value in file2). -p relative Print only differences that are greater than a relative error. relative must be a positive number. The comparison criterion is whether the absolute value of the difference 1 and the ratio of two corresponding values is greater than relative (e.g., |1-(b/a)| > relative where a is a value in file1 and b is a value in file2). object1 object2 Specific object(s) within the files to be compared. EXAMPLES
The following h5diff call compares the object /a/b in file1 with the object /a/c in file2: h5diff file1 file2 /a/b /a/c This h5diff call compares the object /a/b in file1 with the same object in file2: h5diff file1 file2 /a/b And this h5diff call compares all objects in both files: h5diff file1 file2 SEE ALSO
h5dump(1), h5ls(1), h5repart(1), h5import(1), gif2h5(1), h52gif(1), h5perf(1) h5diff(1)
All times are GMT -4. The time now is 07:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy