Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Compare two files and print output Post 303041277 by RudiC on Wednesday 20th of November 2019 04:48:55 AM
Old 11-20-2019
How about - as a zeroth approximation - this:
Code:
awk '
NR == 1         {split ($0, HD)
                 next
                }
NR == FNR       {while (NF < 6) {getline X
                                 $0 = $0 FS X
                                }
                 for (i=1; i<=NF; i++) $i = HD[i] ":\"" $i "\""
                 TMP = $NF
                 sub (OFS $NF,_)
                 REF[TMP] = $0
                 next
                }
                {gsub (/=/, ":")
                 sub (/MOUNTPOINT/, "Mounted")
                }
$NF in REF      {sub ("^" $1 FS, _)
                 $1 = $1
                 print REF[$NF], $0
                }

' OFS=, file2 file1
Filesystem:"/dev/xvda1",Size:"477M",Used:"126M",Avail:"326M",Use%:"28%",TYPE:"part",SIZE:"500M",OWNER:"root",GROUP:"disk",MODE:"brw-rw----",Mounted:"/boot"
Filesystem:"/dev/mapper/VolGroup-lv_root",Size:"37G",Used:"1.4G",Avail:"34G",Use%:"4%",TYPE:"lvm",SIZE:"37.6G",OWNER:"root",GROUP:"disk",MODE:"brw-rw----",Mounted:"/"
Filesystem:"/dev/xvdq",Size:"2.0G",Used:"24M",Avail:"1.8G",Use%:"2%",TYPE:"disk",SIZE:"2G",OWNER:"root",GROUP:"disk",MODE:"brw-rw----",Mounted:"/var/log/audit"
Filesystem:"/dev/xvdp",Size:"6.8G",Used:"27M",Avail:"6.4G",Use%:"1%",TYPE:"disk",SIZE:"7G",OWNER:"root",GROUP:"disk",MODE:"brw-rw----",Mounted:"/var/log"
Filesystem:"/dev/xvdo",Size:"6.8G",Used:"458M",Avail:"6.0G",Use%:"7%",TYPE:"disk",SIZE:"7G",OWNER:"root",GROUP:"disk",MODE:"brw-rw----",Mounted:"/var"
Filesystem:"/dev/xvdn",Size:"2.0G",Used:"3.1M",Avail:"1.9G",Use%:"1%",TYPE:"disk",SIZE:"2G",OWNER:"root",GROUP:"disk",MODE:"brw-rw----",Mounted:"/home"

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to compare lines of two files and print output on screen

hey guys, I have two files both with two columns, I have already created an awk code to ignore certain lines (e.g lines that start with 963) as they wou ld begin with a certain string, however, the rest I have added together and calculated the average. At the moment the code also displays... (3 Replies)
Discussion started by: chlfc
3 Replies

2. Shell Programming and Scripting

compare two files and print the last row into first

suppose fileA vis vis gyh gye gyh fileB vis 23 gyh 21 gye 32 output shud be like in fileA ... vis 23 vis 23 gyh 21 gye 32 gyh 21 (1 Reply)
Discussion started by: cdfd123
1 Replies

3. Shell Programming and Scripting

compare columns from seven files and print the output

Hi guys, I need some help to come out with a solution . I have seven such files but I am showing only three for convenience. filea a5 20 a8 16 fileb a3 42 a7 14 filec a5 23 a3 07 The output file shoud contain the data in table form showing first field of... (7 Replies)
Discussion started by: smriti_shridhar
7 Replies

4. Shell Programming and Scripting

awk to compare flat files and print output to another file

Hello, I am strugling from quite a some time to compare flat files with over 1 million records could anyone please help me. I want to compare two pipe delimited flat files, file1 with file2 and output the unmatched rows from file2 in file3 Sample File1: ... (9 Replies)
Discussion started by: suhaeb
9 Replies

5. Shell Programming and Scripting

compare two files and search keyword and print output

You have two files to compare by searching keyword from one file into another file File A 23 >pp_ANSWER 24 >aa hello 25 >jau head wear 66 >jss oops 872 >aqq olps ploww oww sss 722 >GG_KILLER ..... large files File B Beta done KILLER John Mayor calix meyers ... (5 Replies)
Discussion started by: cdfd123
5 Replies

6. UNIX for Advanced & Expert Users

Shell Script to compare xml files and print output to a file

All, PLease can you help me with a shell script which can compare two xml files and print the difference to a output file. I have attached one such file for you reference. <Group> <Member ID=":Year_Quad:41501" childCount="4" fullPath="PEPSICO Year-Quad-Wk : FOLDER.52 Weeks Ending Dec... (2 Replies)
Discussion started by: kanthrajgowda
2 Replies

7. Shell Programming and Scripting

Compare columns 2 files and print

File 1 has 16 columns so does File 2 I want to remove all records from File 2 that column 1 and column 16 match between file 1 and file 2 delimter of files is ~ (10 Replies)
Discussion started by: sigh2010
10 Replies

8. Shell Programming and Scripting

Compare two files and print using awk

I have 2 files: email_1.out 1 abc@yahoo.com 2 abc_1@yahoo.com 3 abc_2@yahoo.com data_1.out <tr> 1 MAIL # 1 TO src_1 </tr> <tr><td class="hcol">col_id</td> <td class="hcol">test_dt</td> <td class="hcol">user_type</td> <td class="hcol">ct</td></tr> <tr><td... (1 Reply)
Discussion started by: sol_nov
1 Replies

9. Shell Programming and Scripting

Compare two files and print list

Hi Gents, I have 2 files as seen below. File 1: 9 1020 10 1001 11 1001 12 1002 13 1003 14 1004 15 1004 File 2: 9 1000 11 1001 12 1002 13 1003 15 1004 (5 Replies)
Discussion started by: jiam912
5 Replies

10. Shell Programming and Scripting

Compare columns of multiple files and print those unique string from File1 in an output file.

Hi, I have multiple files that each contain one column of strings: File1: 123abc 456def 789ghi File2: 123abc 456def 891jkl File3: 234mno 123abc 456def In total I have 25 of these type of file. (5 Replies)
Discussion started by: owwow14
5 Replies
lucompare(1M)						  System Administration Commands					     lucompare(1M)

NAME
lucompare - compare boot environments SYNOPSIS
/usr/sbin/lucompare [-i infile | -t] [-o outfile] BE_name [-X] /usr/sbin/lucompare [ -C file [-o outfile]] [-X] DESCRIPTION
The lucompare command is part of a suite of commands that make up the Live Upgrade feature of the Solaris operating environment. See live_upgrade(5) for a description of the Live Upgrade feature. The lucompare command compares the contents of the current boot environment (BE) with the contents of another BE. With the -C option, lucompare compares file statistics so that you can determine which files have changed on a BE since a specified time, such as the creation time of a BE. A specified BE must be inactive and in the complete state, as reported by the lustatus(1M) command. Also, a BE cannot have a copy job scheduled, which is also reported by lustatus(1M). A specified BE cannot have any partitions mounted with lumount(1M) or mount(1M). For each file system defined for a specified BE, lucompare compares all files with the files with the same pathnames in the current BE. The files present in the active BE, but not in the specified BE, and vice-versa, are reported. You also have the option to specify a list of files to be compared. If you specify the -C option, instead of doing an absolute comparison of the current BE with a target BE, lucompare compares the files in a specified BE with the list of files recorded in a file. When a BE is created, lucreate(1M) creates a file named :<BE_name> in /etc/lu/com- pare. You can use the -C option to compare the files in a specified BE to this snapshot in /etc/lu/compare or you can compare the BE to a file previously created with the -o option. Comparing a BE to its own snapshot in /etc/lu/compare enables you to determine which files have changed on the BE since its creation. By default, the output of lucompare is written to stdout. With the -C option, you must use the -o option to specify an output file. The output for lucompare is a list of files that differ in permissions, owner, group, or sum, along with the reason for difference. The output format is shown below: > active BE < BE_name reason > file_name:owner:group:number_of_links:mode:type: size or major_minor number:checksum < file_name:owner:group:number_of_links:mode:type: size or major_minor number:checksum The above fields are obtained from the stat(2) structure of the file. The type field can be one of the following: SYMLINK symbolic link FIFO FIFO file CHRSPC character special BLKSPC block special DIR directory REGFIL regular file UNKNOW unknown file type lucompare computes checksums only if the file on the specified BE matches its counterpart on the active BE in all of the fields described above. If the checksums differ, lucompare appends the differing checksums to the entries for the compared files. The lucompare command requires root privileges. OPTIONS
The lucompare command has the following options: -C file Compare file statistics of BE with those recorded in file. file can be the snapshot created at BE creation time, /etc/lu/compare/:<BE_name>, or a file previously created with the -o option. You must use the -o option with this option. -i infile Compare files listed in infile. The files to be compared should be an absolute filename. If the entry in the file is a directory, then comparison is recursive with respect to the directory. Mutually exclusive of -t. -o outfile Send output of differences to outfile. You must use this option if you use -C. -t Compare only nonbinary files. This is achieved by performing a file(1) command on each file in the tree walk and only comparing text files. Mutually exclusive of -i. -X Enable XML output. Characteristics of XML are defined in DTD, in /usr/share/lib/xml/dtd/lu_cli.dtd.<num>, where <num> is the version number of the DTD file. OPERANDS
BE_name Name of the BE to which the active BE will be compared. You cannot specify a BE that is involved in another Live Upgrade operation, or specify a BE for which you have mounted partitions (using lumount(1M) or mount(1M)). EXAMPLES
Example 1: Checking Differences Since BE Creation The following command lists the differences in the BE s8u5 between its creation time and the present. # lucompare -C /etc/lu/compare/:s8u5 -o /var/tmp/compare.out s8u5 Note that /etc/lu/compare/:s8u5 is the file created by lucreate upon creation of a BE. The list of differences is sent to /var/tmp/com- pare.out. EXIT STATUS
The following exit values are returned: 0 Successful completion. >0 An error occurred. FILES
/etc/lutab list of BEs on the system /usr/share/lib/xml/dtd/lu_cli.dtd.<num> Live Upgrade DTD (see -X option) ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWluu | +-----------------------------+-----------------------------+ SEE ALSO
lu(1M), luactivate(1M), lucancel(1M), lucreate(1M), lucurr(1M), ludelete(1M), ludesc(1M), lufslist(1M), lumake(1M), lumount(1M), lure- name(1M), lustatus(1M), luupgrade(1M), lutab(4), attributes(5), live_upgrade(5) NOTES
The lucompare command makes no attempt to reconcile any differences it detects between BEs. SunOS 5.10 21 Dec 2001 lucompare(1M)
All times are GMT -4. The time now is 10:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy