Sponsored Content
Top Forums Shell Programming and Scripting Awk script / comparing two files Post 302363952 by ripat on Wednesday 21st of October 2009 05:10:56 PM
Old 10-21-2009
Hi,

Try this:

Code:
awk -F"|" -v OFS="|" 'FNR==NR{a[$1]=$2;next}a[$1]{$12=a[$1]}1' file2 file1

And please edit your post and use the code tags.

Last edited by ripat; 10-21-2009 at 06:16 PM.. Reason: fixed
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

comparing two files using awk.

Hi All, a new bie to awk, How to compare substring of col1,file 1 with col2file2 and get file1contents+col3file2 as output. file1 ----- kumarfghh,23,12000,5000 rajakumar,24,14000,2500 rajeshchauhan,25,16000,2600 manoj,26,17000,2300 file 2 -------- 123,kumar,US, 123,sukumar,UK... (4 Replies)
Discussion started by: jerome Sukumar
4 Replies

2. Shell Programming and Scripting

Comparing two files using awk

Hi, I have 2 text files n1 and n2. cat n1 : -------- 1234567890 4444444444 cat n2 : --------- 1234567890 4444444444 7777777777 8888888888 they are some sample records. File n1 contains some lookup records, whereas file n2 contains some transaction records. I need to get the... (2 Replies)
Discussion started by: kanu_kanu
2 Replies

3. Shell Programming and Scripting

awk - comparing files

I've been trying to use awk to compare two files that have pretty much the same data in apart from certain lines where in one file a fields value has changed. I want to print the line from the first file and the changed line from the second file. At the moment, all I can get it to do is print the... (6 Replies)
Discussion started by: dbrundrett
6 Replies

4. Shell Programming and Scripting

awk script issue : comparing two files with a pattern

File 1 ################################################################# pma.zcal.iop_pma_zcal_cntl (2710.080 115.200) pma.lanea23.rx0.cntl (696.960 844.800) pma.lanea67.rx0.cntl (1733.760 844.800) pma.zcal.iop_pma_zcal_cust (2280.960 115.200)... (1 Reply)
Discussion started by: jaita
1 Replies

5. Shell Programming and Scripting

comparing two files using awk

hit brick wall while trying to knock up a script that will take values from the "lookup" file and look it up in the "target" file and return values that dont appear in "target" but do in "lookup". just knocked up something using bits from previous threads but theres gotta be something wrong... (13 Replies)
Discussion started by: jack.bauer
13 Replies

6. UNIX for Advanced & Expert Users

Comparing two files using awk

i have one file say file1 having many records.Each record contains 2000 characters.i have to compare 192-200 (stored as name)characters in this file from other file say file2 having name stored in 1-9 characters. after comparing i have to print the record from file1 in another file say file3 ... (3 Replies)
Discussion started by: sonam273
3 Replies

7. Shell Programming and Scripting

comparing 2 files with awk

Hi, I'm a new user in awk and i'm trying to compare two files to create a third one if some values match in both files. The first file has this content: s 45.960746365 _21_ AGT 2490 [21:0 22:0 s 45.980418496 _21_ AGT 2491 [21:0 22:0 s 46.000090627 _21_ AGT 2492 [21:0 22:0 s 47.906552206... (2 Replies)
Discussion started by: carlosoria
2 Replies

8. Shell Programming and Scripting

Comparing the matches in two files using awk when both files have their own field separators

I've two files with data like below: file1.txt: AAA,Apples,123 BBB,Bananas,124 CCC,Carrot,125 file2.txt: Store1|AAA|123|11 Store2|BBB|124|23 Store3|CCC|125|57 Store4|DDD|126|38 So,the field separator in file1.txt is a comma and in file2.txt,it is | Now,the output should be... (2 Replies)
Discussion started by: asyed
2 Replies

9. Shell Programming and Scripting

awk for comparing two files

so have file1 like this: joe 123 jane 456 and then file2 like this: 123 left right 456 up down joe ding dong jane flip flop what I need to do is compare col1 and col2 in file1 with col1 in file2 and generate a new file that has lines like this: joe 123 ding dong left right jane... (11 Replies)
Discussion started by: Jaymz
11 Replies

10. Shell Programming and Scripting

Comparing the two files using awk script

Hi all, Can you please help me to find out that where is the problem in my script or either my way of writing the shell command on the prompt is not right? Actually, I want to compare the second column "$1" of the file "t1" with all the columns of second file "t2", if there is a match then the... (2 Replies)
Discussion started by: coder83
2 Replies
MYSQL_FETCH_FIELD(3)							 1						      MYSQL_FETCH_FIELD(3)

mysql_fetch_field - Get column information from a result and return as an object

SYNOPSIS
Warning This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include: omysqli_fetch_field(3) o PDOStatement::getColumnMeta object mysql_fetch_field (resource $result, [int $field_offset]) DESCRIPTION
Returns an object containing field information. This function can be used to obtain information about fields in the provided query result. o $ result -The result resource that is being evaluated. This result comes from a call to mysql_query(3). o $field_offset - The numerical field offset. If the field offset is not specified, the next field that was not yet retrieved by this function is retrieved. The $field_offset starts at 0. Returns an object containing field information. The properties of the object are: o name - column name o table - name of the table the column belongs to, which is the alias name if one is defined o max_length - maximum length of the column o not_null - 1 if the column cannot be NULL o primary_key - 1 if the column is a primary key o unique_key - 1 if the column is a unique key o multiple_key - 1 if the column is a non-unique key o numeric - 1 if the column is numeric o blob - 1 if the column is a BLOB o type - the type of the column o unsigned - 1 if the column is unsigned o zerofill - 1 if the column is zero-filled Example #1 mysql_fetch_field(3) example <?php $conn = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$conn) { die('Could not connect: ' . mysql_error()); } mysql_select_db('database'); $result = mysql_query('select * from table'); if (!$result) { die('Query failed: ' . mysql_error()); } /* get column metadata */ $i = 0; while ($i < mysql_num_fields($result)) { echo "Information for column $i:<br /> "; $meta = mysql_fetch_field($result, $i); if (!$meta) { echo "No information available<br /> "; } echo "<pre> blob: $meta->blob max_length: $meta->max_length multiple_key: $meta->multiple_key name: $meta->name not_null: $meta->not_null numeric: $meta->numeric primary_key: $meta->primary_key table: $meta->table type: $meta->type unique_key: $meta->unique_key unsigned: $meta->unsigned zerofill: $meta->zerofill </pre>"; $i++; } mysql_free_result($result); ?> Note Field names returned by this function are case-sensitive. Note If field or tablenames are aliased in the SQL query the aliased name will be returned. The original name can be retrieved for instance by using mysqli_result::fetch_field. mysql_field_seek(3). PHP Documentation Group MYSQL_FETCH_FIELD(3)
All times are GMT -4. The time now is 10:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy