Sponsored Content
Top Forums Shell Programming and Scripting how to search string and number in one file and check in the other file Post 302133383 by aigles on Thursday 23rd of August 2007 06:51:53 AM
Old 08-23-2007
The script works fine for me :

Code:
$ cat file1.log
fileset 999 primary-ilist inode 31538 dup block
fileset 999 primary-ilist inode 31558 dup block
fileset 999 primary-ilist inode 31622 dup block
fileset 999 primary-ilist inode 32785 dup block
fileset 999 primary-ilist inode 36992 dup block
fileset 999 primary-ilist inode 36994 dup block
$ cat file2.log
/export/var/opt/novell/edirectory:
total 768860
33365 drwxr-xr-x 6 root root 1024 Nov 17 2006 .
65 drwxr-xr-x 3 root other 96 Sep 1 2006 ..
32793 -rw------- 1 root root 194379776 Sep 1 2006 NDO.01
32792 -rw------- 1 root root 262144 Sep 1 2006 NDO.db
32782 -rw------- 1 root root 0 Sep 1 2006 NDO.lck
32794 drwx------ 2 root root 96 Sep 1 2006 NDO.rfl
37480 drwxr-xr-x 2 root root 96 Nov 24 2005 StatLog
32791 -rw-r--r-- 1 root root 132 Nov 17 2006 _ndsdb.ini
32781 -rw-r--r-- 1 root root 403 Nov 24 2005 attributeIndex.ldif
32776 -rw-r--r-- 1 root root 13218 Nov 24 2005 attributeSchema.ldif
32779 drw------- 3 root root 96 Nov 24 2005 certserv
32785 -rw------- 1 root root 198705152 Aug 22 2007 nds.01

$ cat knshree2.sh
awk '

# file2

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

# file1

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

' file2.log file1.log
$ knshree2.sh
fileset 999 primary-ilist inode 31538 dup block -> Not exist
fileset 999 primary-ilist inode 31558 dup block -> Not exist
fileset 999 primary-ilist inode 31622 dup block -> Not exist
fileset 999 primary-ilist inode 32785 dup block -> /export/var/opt/novell/edirectory
fileset 999 primary-ilist inode 36992 dup block -> Not exist
fileset 999 primary-ilist inode 36994 dup block -> Not exist
$

Jean-Pierre.
 

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
ncheck_vxfs(1M) 														   ncheck_vxfs(1M)

NAME
ncheck_vxfs - generate path names from inode numbers for a VxFS file system SYNOPSIS
[ generic_options ] DESCRIPTION
generates a list of path names corresponding to inode numbers for files in a specified VxFS file system. You can specify a range for some options. A range can be a single number or two numbers separated by a hyphen (-). The range is inclu- sive. If you enter a hyphen and omit the first number, the range begins at zero. If you omit the second number, the range ends at the end of the file system. Names of directory files are followed by slash dot (/.). OPTIONS
generic_options Supported by the generic command. See ncheck(1M). Specifies the VxFS file system type. Allow printing of the names dot and dot dot which are ordinarily suppressed. Limit the report to the files on the inode list, ilist, that follows. The ilist must be separated by commas without spaces. Specifies options specific to the VxFS file system type. specific_options is a list of suboptions or keyword/attribute pairs. Prints the path name containing file system block number block. Prints information on all inodes containing or referencing block numbers in the specified range. The output format is the same as that for but the units used are file system blocks instead of sectors. Lists the files residing in the specified Storage Checkpoint. Specifies the device ID. Used for multi-volume file systems. If the option is not specified, is run on all available devices. If is specified, all subsequent block or sector ranges are scanned for the device specified by devid. Prints mode information (used in conjunction with the generic option). Reports on all inodes containing or referencing the sectors in sector_range. The output includes the inode number, fileset index of the inode, sectors contained, and the path name or inode type. Inodes searched include structural inodes and attribute inodes, so a path name is only generated when the sector is contained by a file. If the sector is not contained in any file, is dis- played for the inode type. Multiple options accumulate. Performs a surface analysis. If a sector_range is specified, performs a surface analysis only for that range. All the sector are read and if the read of a sector fails, its sector number is printed. If any bad sectors are found, treats the list of bad sectors as input to the option and produces a list containing or referencing inodes. Report only on special files and regular files with set-user-ID mode. This option may be used to detect violations of security policy. Report on files containing or referencing the specified sector(s). Output consists of the fileset name, fileset index, inode number, and pathname of file or file type if a struc- tural inode or attribute inode. Sectors not allocated to any file or file system structure are reported as Sec- tors not part of the file system are reported as Unused or irrelevant fields are printed as sector_list consists of one or more ranges of sector numbers, separated by commas without intervening spaces. Multiple options accumulate. Prints the completed command, but does not perform any action. EXAMPLES
Report on all inodes or file system structures containing or referencing sector 20 through 35 (inclusive) in the file system The following command is same as above, but reports on all inodes or file system structures referencing any sector in the file system: Report on a specified range of block numbers (partial output shown): ncheck -F vxfs -oblock=- /dev/vx/rdsk/vset5 /dev/vx/rdsk/vset5: sectors(50331648) blocks(0) ----------------- ----------------- 0/0-0/16777215 0/0-0/8388608 1/0-1/16777215 1/0-1/8388608 2/0-2/16777215 2/0-2/8388608 fileset fset mtch match devid/ name indx inode indx inode blocks name ---------- ---- ------ ---- ------ ------------- ------------------ STRUCTURAL 1 3 - 35 0/9-0/10 <fileset_header> STRUCTURAL 1 4 1 - 0/11-0/14 <inode_alloc_unit> STRUCTURAL 1 5 1 37 0/7440-0/7447 <inode_list> STRUCTURAL 1 5 1 37 0/24-0/31 <inode_list> STRUCTURAL 1 5 1 37 0/7432-0/7439 <inode_list> STRUCTURAL 1 5 1 37 0/16-0/23 <inode_list> STRUCTURAL 1 6 - - 0/15 <current_usage_tbl> . . . UNNAMED 999 25 - - 2/80-2/84 /exec.h UNNAMED 999 26 - - 2/86-2/87 /exechdr.h - - - - - 0/6808 <free> - - - - - 0/6823-0/6975 <free> List the files in the Storage Checkpoint named on the device Report all inodes and file system structures referencing any sector in the device with devid 2 in the file system DIAGNOSTICS
When the file system structure is not correct, prints three question marks (???) to denote the "parent" of a parentless file. A path name beginning with dot dot dot indicates a loop. A path name beginning with three asterisks denotes a directory entry whose dot dot entry does not correspond with the directory in which it was found. SEE ALSO
sort(1), fsckptadm(1M), fsck_vxfs(1M), ncheck(1M), fs_vxfs(4). ncheck_vxfs(1M)
All times are GMT -4. The time now is 06:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy