Sponsored Content
Top Forums Shell Programming and Scripting Compare two files and print the two lines with difference Post 302327243 by kingpeejay on Saturday 20th of June 2009 10:01:10 AM
Old 06-20-2009
Compare two files and print the two lines with difference

I have two files like this:
#FILE 1
ABCD 4322 26485
JMTJ 5311 97248
XMPJ 4321 58978
#FILE 2
ABCD 4321 26485
JMTJ 5311 97248
XMPJ 4321 68978

What to do: Compare the two files and find those lines that doesn't match. And have a new file like this:
#FILE 3
"from file 1"
ABCD 4322 26485
XMPJ 4321 58978

"from file 2"
ABCD 4321 26485
XMPJ 4321 68978

many thanks!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

to compare two files and to print the difference

suppose one file P1168S P2150L P85L Q597R R1097C Another file P2150L P85L Q597R R1097C R1379C R1587K Then output shud be R1379C R1587K thanks (5 Replies)
Discussion started by: cdfd123
5 Replies

2. 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

3. Shell Programming and Scripting

Compare selected columns from a file and print difference

I have learned file comparison from my previous post here. Then, it is comparing the whole line. Now, i have a new problem. I have two files with 3 columns separated with a "|". What i want to do is to compare the second and third column of file 1, and the second and third column of file 2. And... (4 Replies)
Discussion started by: kingpeejay
4 Replies

4. Shell Programming and Scripting

Compare two columns in two files and print the difference

one file . . importing table employee 119 . . importing table jobs 1 2nd file . . importing table employee 120 . . importing table jobs 1 and would like... (2 Replies)
Discussion started by: jhonnyrip
2 Replies

5. UNIX for Dummies Questions & Answers

Compare 2 files print the lines of file 2 that contain a string from file 1

Hello I am a new unix user, and I have a work related task to compare 2 files and print all of the lines in file 2 that contain a string from file 1 Note: the fields are in different columns in the files. I suspect the is a good use for awk? Thanks for your time & help File 1 123 232 W343... (6 Replies)
Discussion started by: KevinRidley
6 Replies

6. Shell Programming and Scripting

Compare multiple files and print unique lines

Hi friends, I have multiple files. For now, let's say I have two of the following style cat 1.txt cat 2.txt output.txt Please note that my files are not sorted and in the output file I need another extra column that says the file from which it is coming. I have more than 100... (19 Replies)
Discussion started by: jacobs.smith
19 Replies

7. Shell Programming and Scripting

Compare file1 for matching line in file2 and print the difference in matching lines

Hello, I have two files file 1 and file 2 each having result of a query on certain database tables and need to compare for Col1 in file1 with Col3 in file2, compare Col2 with Col4 and output the value of Col1 from File1 which is a) not present in Col3 of File2 b) value of Col2 is different from... (2 Replies)
Discussion started by: RasB15
2 Replies

8. Shell Programming and Scripting

Simple awk command to compare two files and print first difference

Hello, I have two text files, each with a single column, file 1: 124152970 123899868 123476854 54258288 123117283 file 2: 124152970 123899868 54258288 123117283 122108330 (5 Replies)
Discussion started by: LMHmedchem
5 Replies

9. Shell Programming and Scripting

Compare two variables and print the difference

Hi PRIM_SEQ=`some sql code` and output of PRIM_SEQ is like below 120 130 STB_SEQ=`some sql code` and output of STB_SEQ is like below 115 110 i need to compare this two variables output ( decimal numbers) 1) What I want to do is to compare every number in the PRIM_SEQ with... (8 Replies)
Discussion started by: amar1208
8 Replies

10. UNIX for Beginners Questions & Answers

Compare two variables and print the difference

compare two variables and print the difference i have two variables X1=rac1,rac2 Y1=rac2,rac3 output=rac1,rac3 Use code tags to wrap code fragments or data samples. (1 Reply)
Discussion started by: jhonnyrip
1 Replies
PMNEWCONTEXT(3) 					     Library Functions Manual						   PMNEWCONTEXT(3)

NAME
pmNewContext - establish a new PMAPI context C SYNOPSIS
#include <pcp/pmapi.h> int pmNewContext(int type, const char *name); cc ... -lpcp DESCRIPTION
An application using the Performance Metrics Application Programming Interface (PMAPI) may manipulate several concurrent contexts, each associated with a source of performance metrics, e.g. pmcd(1) on some host, or an archive log of performance metrics as created by pmlog- ger(1), or a standalone connection on the local host that does not involve pmcd(1). pmNewContext may be used to establish a new context. The source of the metrics is identified by name, and may be either a host name (type is PM_CONTEXT_HOST), or the base name common to all of the physical files of an archive log (type is PM_CONTEXT_ARCHIVE). For a type of PM_CONTEXT_HOST, in addition to identifying a host the name may also be used to encode additional optional information in the form of a pmcd(1) port number, a pmproxy(1) hostname and a proxy port number. For example the name "app23:14321,4321@firewall.exam- ple.com:11111" specifies a connection on port 14321 (or port 4321 if 14321 is unavailable) to pmcd(1) on the host app23 via port 11111 to pmproxy(1) on the host firewall.example.com. For a type of PM_CONTEXT_ARCHIVE, name may also be the name of any of the physical files of an archive, e.g. myarchive.meta (the metadata file) or myarchive.index (the temporal index) or myarchive.0 (the first data volume of the archive) or myarchive.0.bz2 or myarchive.0.bz (the first data volume compressed with bzip2(1)) or myarchive.0.gz or myarchive.0.Z or myarchive.0.z (the first data volume compressed with gzip(1)), myarchive.1 or myarchive.3.bz2 or myarchive.42.gz etc. In the case where type is PM_CONTEXT_LOCAL, name is ignored, and the context uses a standalone connection to the PMDA methods used by pmcd(1). When this type of context is used, the range of accessible performance metrics is constrained to those from the operating system, and optionally the ``proc'', ``sample'' and ``ib'' PMDAs. In the case where type is PM_CONTEXT_HOST, additional flags can be added to the type to indicate if the connection to pmcd(1) should be encrypted (PM_CTXFLAG_SECURE), deferred (PM_CTXFLAG_SHALLOW) and if the file descriptor used to communicate with pmcd(1), should not be shared across contexts (PM_CTXFLAG_EXCLUSIVE). These final two context flags are now deprecated and ignored. The initial instance profile is set up to select all instances in all instance domains. In the case of an archive, the initial collection time is also set to zero, so that an initial pmFetch(3) will result in the earliest set of metrics being returned from the archive. Once established, the association between a context and a source of metrics is fixed for the life of the context, however routines are pro- vided to independently manipulate both the instance profile (see pmAddProfile(3) and pmDelProfile(3)) and the collection time for archives (see pmSetMode(3)). pmNewContext returns a handle that may be used with subsequent calls to pmUseContext(3). The new context remains the current PMAPI context for all subsequent calls across the PMAPI, until another call to pmNewContext(3) is made, or the context is explicitly changed with a call to pmDupContext(3) or pmUseContext(3), or destroyed using pmDestroyContext(3). When attempting to connect to a remote pmcd(1) on a machine that is booting, pmNewContext could potentially block for a long time until the remote machine finishes its initialization. pmNewContext will abort and return an error if the connection has not been established after some specified interval has elapsed. The default interval is 5 seconds. This may be modified by setting PMCD_CONNECT_TIMEOUT in the envi- ronment to a real number of seconds for the desired timeout. This is most useful in cases where the remote host is at the end of a slow network, requiring longer latencies to establish the connection correctly. ENVIRONMENT
PMCD_CONNECT_TIMEOUT Timeout period (in seconds) for pmcd(1) connection attempts. PMCD_PORT TCP/IP port(s) for connecting to pmcd(1), historically was 4321 and more recently the officially registered port 44321; in the cur- rent release, pmcd listens on both these ports as a transitional arrangement. If used, should be set to a comma-separated list of numerical port numbers. PMDA_PATH When searching for PMDAs to be loaded when type is PM_CONTEXT_LOCAL, the PMDA_PATH environment variable may be used to define a search path of directories to be used to locate the PMDA executables. The default search path is $PCP_SHARE_DIR/lib:/usr/pcp/lib. CAVEATS
When using a type of PM_CONTEXT_LOCAL, the operating system PMDA may export data structures directly from the kernel, which means that the pmNewContext caller should be an executable program compiled for the same object code format as the booted kernel. In addition, applications using a PM_CONTEXT_LOCAL context must be single-threaded because the various DSO PMDAs may not be thread-safe. This restriction is enforced at the PMAPI(3), where routines may return the error code PM_ERR_THREAD if the library detects calls from more than one thread. Applications that use gethostbyname(3N) should exercise caution because the static fields in struct hostent may not be preserved across some PMAPI(3) calls. In particular, pmNewContext(3) and pmReconnectContext(3) both may call gethostbyname(3N) internally. SEE ALSO
pmcd(1), pmproxy(1), pmAddProfile(3), PMAPI(3), pmDelProfile(3), pmDestroyContext(3), pmDupContext(3), pmGetConfig(3), pmReconnectCon- text(3), pmSetMode(3), pmUseContext(3), pmWhichContext(3), pcp.conf(5) and pcp.env(5). DIAGNOSTICS
PM_ERR_PERMISSION No permission to perform requested operation PM_ERR_CONNLIMIT PMCD connection limit for this host exceeded PM_ERR_NOCONTEXT Requested context type was not PM_CONTEXT_LOCAL, PM_CONTEXT_HOST or PM_CONTEXT_ARCHIVE. Performance Co-Pilot PCP PMNEWCONTEXT(3)
All times are GMT -4. The time now is 07:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy