Sponsored Content
Operating Systems Linux Ubuntu Match col 1 of File 1 with col 1 File 2 and create a 3rd file Post 302329993 by sogi on Tuesday 30th of June 2009 02:10:28 AM
Old 06-30-2009
Both files have no headings

input of file 1 (has one 1 column, as shown below):

MXY2344
MXY2455
.
.
.
.
.
.
.
MXY9150 <--- row #364



input of file 2 (this file has 2,498,588 columns with single digit numbers, starting with column 1 as shown below, each column is separated by a space)

MXY2344
MXY2455
.
.
.
.
.
.
.
MXY9150 <--- row #364
.
.
.
.
.
.
.
.
.
.
.
MXY9423 <--- row #1411


desired output file 3 (with only #364 rows with the ids matched between file1 and file2 and 2,498,588 columns)

MXY2344
MXY2455
.
.
.
.
.
.
.
MXY9150 <--- row #364

Thank you for any help!

---------- Post updated at 11:10 PM ---------- Previous update was at 11:03 PM ----------

I just checked the results I obtained with grep -A1 -A1 -f file1.txt file2 > file3

and they are wrong. Instead of getting only 364 rows, I get 367 and some of the ids of file 1 are missing in the output file 3. I want to match the ids from file1 (my "golden" list) in file2 and output that in file 3
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sum(col) finding from a file

Hi I have an file which looks like country address phone amount sweden |address |phone | 10 | Singapo |address |phone | 20 | Italy-N |address |phone | 30 | denmar |address |phone | 40 | Here i need to do the sum(amount), how to do this in shell scripting Thanks Babu (11 Replies)
Discussion started by: ksmbabu
11 Replies

2. Shell Programming and Scripting

sort and split file by 2 cols (1 col after the other)

Dear All, I am a newbie to shell scripting so this one is really over my head. I have a text file with five fields as below: 76576.867188 6232.454102 2.008904 55.000000 3 76576.867188 6232.454102 3.607231 55.000000 4 76576.867188 6232.454102 1.555146 65.000000 3 76576.867188 6232.454102... (19 Replies)
Discussion started by: Ghetz
19 Replies

3. Shell Programming and Scripting

Compare - 1st col of file

Hi, I have two different files, one has two columns and other has only one column. I would like to compare the first column in the first file with the data in the second file and write a third file with the data that is not present is not common to them. First file:... (26 Replies)
Discussion started by: swame_sp
26 Replies

4. Shell Programming and Scripting

Get columns from another file for match in col 2 in 1st file

Hi, My first file has 592155 9 rs16916098 1 592156 19 rs7249604 1 592157 4 rs885156 1 592158 5 rs350067 12nd file has 9 rs16916098 0 113228129 2 4 19 rs7249604 0 58709070 4 2 2 rs17042833 0 113558750 4 2... (2 Replies)
Discussion started by: genehunter
2 Replies

5. Shell Programming and Scripting

how to add new col in a file

Hi, Experts, I have a requirement as following: my source file: a a a b b c c c c I need add one more colume as following: 1 a 2 a 3 a 1 b 2 b 1 c 2 c (4 Replies)
Discussion started by: ken002
4 Replies

6. UNIX for Advanced & Expert Users

Print line based on highest value of col (B) and repetion of values in col (A)

Hello everyone, I am writing a script to process data from the ATP world tour. I have a file which contains: t=540 y=2011 r=1 p=N409 t=540 y=2011 r=2 p=N409 t=540 y=2011 r=3 p=N409 t=540 y=2011 r=4 p=N409 t=520 y=2011 r=1 p=N409 t=520 y=2011 r=2 p=N409 t=520 y=2011 r=3 p=N409 The... (4 Replies)
Discussion started by: imahmoud
4 Replies

7. Shell Programming and Scripting

Printing from col x to end of line, except last col

Hello, I have some tab delimited data and I need to move the last col. I could hard code it, awk '{ print $1,$NF,$2,$3,$4,etc }' infile > outfile but it would be nice to know the syntax to print a range cols. I know in cut you can do, cut -f 1,4-8,11- to print fields 1,... (8 Replies)
Discussion started by: LMHmedchem
8 Replies

8. Shell Programming and Scripting

Run a program-print parameters to output file-replace op file contents with max 4th col

Hi Friends, This is the only solution to my task. So, any help is highly appreciated. I have a file cat input1.bed chr1 100 200 abc chr1 120 300 def chr1 145 226 ghi chr2 567 600 unix Now, I have another file by name input2.bed (This file is a binary file not readable by the... (7 Replies)
Discussion started by: jacobs.smith
7 Replies

9. Shell Programming and Scripting

Modifying col values based on another col

Hi, Please help with this. I have several excel files (with and .xlsx format) with 10-15 columns each. They all have the same type of data but the columns are not ordered in the same way. Here is a 3 column example. What I want to do add the alphabet from column 2 to column 3, provided... (9 Replies)
Discussion started by: newbie83
9 Replies

10. Shell Programming and Scripting

Replace col 23 - 26 with new value, non delimited file

hello, i have a undelimited file which contains 229 byte records. i want to change column 23 - 26 with a new value and also change the sign of the data in colulmn 30 - 70. i've tried SED for the first change, but nothing happens: sed 's/\(^.\{22\}\).\{4\}\(.*\)/\0603\2/' inputfile heres an... (8 Replies)
Discussion started by: blt123
8 Replies
acctmerg(8)						      System Manager's Manual						       acctmerg(8)

NAME
acctmerg - Merges total-accounting files into an intermediary file or a daily accounting file SYNOPSIS
acctmerg -[ahipv] [specification] -[tu] [file ....] FLAGS
Produces output as ASCII records. Lists column headings. This flag implies -a but is effective with the -p or -v flags. Expects input files to have ASCII records that are converted to binary output records. Lists input but without processing. Produces a single record that contains the totals of all input. Summarizes by user ID rather than by user name. This is convenient when a single user ID is allo- cated to more than one user name. Produces output in ASCII, with more precise notation for floating-point values. DESCRIPTION
The acctmerg command combines process, connect time, fee, disk usage, and queuing (printer) total-accounting records in tacct binary or tacct ASCII format (see the tacct structure in the acct.h file format for a description of this total-accounting format). The acctmerg com- mand writes the results of record processing to standard output. The accounting file produced by the acctmerg command may have entries for as many as 18 columns. Column headings are printed only when you use the -h flag. The following table lists the column headings by number, the column heading by label, and the purpose of the entry: User ID. This is the integer value of the user ID from the /etc/passwd file. User login name. This is the alpha user login name from the /etc/passwd file. Prime-time CPU run time. This is the total time in seconds that prime-time CPU run time was charged to the user during the active accounting period. Nonprime-time CPU run time. This is the total time in seconds that nonprime-time CPU run time was charged to the named user. Prime-time memory K-core. This is a measure of memory usage during prime time. This value expresses the amount of memory used and the elapsed amount of prime time during which it was used (K-core is the product of total CPU time in minutes and mean size of memory used). Nonprime-time memory K-core. This is a measure of memory usage during nonprime time. Prime-time read and write characters. This is the total number of characters transferred during prime-time opera- tion. Nonprime-time read and write characters. This is the total number of characters transferred during nonprime-time operation. Prime- time number of I/O blocks. This is the total number of I/O blocks transferred during prime-time read and write operations. The number of bytes in an I/O block is implementation dependent. Nonprime-time number of I/O blocks. This is the total number of I/O blocks transferred during nonprime-time read and write operations. Prime-time connect duration. This is the total number of prime-time seconds during which a connection existed. Nonprime-time connect duration. This is the total number of nonprime-time seconds during which a connection existed. Disk blocks used. This is the total number of disk blocks used. Number of pages printed. This is the total number of pages queued to any printers in the system. Special fee charge units. This is the number of integer units to charge for any special fee. This value is the one supplied when the /usr/sbin/acct/chargefee command is processed during the active accounting period. Number of processes. This is the total number of processes spawned by the user during the active accounting period. Number of logins. This is the total number of times the user logged in during the active accounting period. Number of disk-accounting samples. This is the total number of times during the active accounting period that the disk-accounting command was used to get the total number of disk blocks listed in the DSK_BLOCKS column. When the value in the DSK_BLOCKS column is divide by this number, the average number of disk blocks used during the accounting period is obtained. Total accounting records are read from standard input and any additional files (up to nine) you specify with the file parameter. File records are merged according to identical keys, usually the user ID and user login name. To optimize processing performance, output is written in binary, unless the -a or -v flag is used. Normally the acctmerg command is called from the runacct shell procedure, either to produce an intermediate file (/var/adm/acct/nite/daytacct, for example) when one or more source accounting files is full, or to merge intermediate files into a cumula- tive total (/var/adm/acct/sum/tacct, is another example). The cumulative total daily files are the source from which the monacct command produces an ASCII monthly summary file, which is written to the /var/adm/acct/fiscal subdirectory. The optional specification parameter allows you to select input or output column entries, as illustrated in Example 1. Field specifications are a comma-separated string of field numbers. Field numbers are referenced in boldface type in the first column of the foregoing list together with their respective column headings. When you specify field numbers they should be listed in the order specified by the bold- faced heading reference numbers. Inclusive field ranges may also be specified, with array sizes properly taken into account except for the ta_name number of characters. For example, -h2-3,11,15-13,2 displays the LOGNAME (2), PRI_CPU (3), PRI_CONNECT time (11), FEES (15), PRINT (14), DISK_BLOCKS (13), and again LOGNAME (2), in that order, with the described column headings (-h). The default specification is to output all 18 columns (1-18 or 1-), which produces rather wide output records that contain all the available accounting data. Queuing system, disk usage, or fee data can be converted into tacct records with the acctmerge command, using the -i flag and the specifi- cation parameter. EXAMPLES
To merge inclusive fields from an ASCII disk-accounting file called dacct into an existing total-accounting file named tacct as binary information, but with entries for fields 1, 2, 13, and 18 only, enter the following line: acctmerg -i 1 -2,13,18 <dacct | acctmerg tacct >output The acctmerg command reads the columnar entries for UID (1), LOGNAME (2), DSK_BLOCKS (13), and DSAMPS (18) from the dacct file as input, merges this information as tacct binary records, and writes the result to standard output as ASCII. To repair file jan2.rpt in inclusive tacct columnar format, enter the following initial command, edit the jan2.tmp file, and then enter the last command: acctmerg -v <jan2.rpt >jan2.tmp Edit jan2.tmp as desired.... acctmerg -i >jan2.tmp >jan2.rpt The first command redirects the content of file jan2.rpt to file jan2.tmp, with ASCII output and floating-point values. After you edit file jan2.tmp, the last command redirects file jan2.tmp as ASCII input to file jan2.rpt as output, with output records in binary. FILES
Specifies the command path. Accounting header files that define formats for writing accounting files. This is where prime time is set. Intermediate daily total-accounting file. Cumulative total-accounting file. RELATED INFORMATION
Commands: acct(8), acctcms(8), acctcom(8), acctcon(8), acctdisk(8), acctprc(8), fwtmp(8), runacct(8), wtmpconvert(8). Functions: acct(2). delim off acctmerg(8)
All times are GMT -4. The time now is 02:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy