Sponsored Content
Top Forums Shell Programming and Scripting Awk: Replacement using 2 diff files input and comparison Post 302883402 by siramitsharma on Tuesday 14th of January 2014 12:56:01 AM
Old 01-14-2014
Awk: Replacement using 2 diff files input and comparison

Requirement:
If $5(date field) in ipfile is less than $7(date field) in deact file & $1 of ipfile is present in deactfile then
$1 to be replaced by $2,$3,$4,$5,$6 of deact file
else if $5(date field) in ipfile is greater than $7(date field) in actfile & $1 of ipfile is present in actfile then
$1 to be replaced by $2,$3,$4,$5,$6 of actfile.


IPFILE
Code:
8104665534|2|404001742933540|180.215.139.144|20140114100944|20140114101027|43|20140114101045|3756|13054|31|26|59|44700kth|70|1|internet@internet.mtsindia.in|34661
8104665534|2|404001742933541|180.215.139.144|20131114101045|20131115101045|0|20131115101045|0|0|0|0|59|44700kth|68|1|internet@internet.mtsindia.in|34661
8
9136713486|2|405891614985516|180.215.176.110|20140114093453|20140114100922|2069|20140114101001|1658883|196181|114597376|3801088|59|46600g0W|70|1|internet@internet.mtsindia.in|32852
9136713486|2|405891614985516|180.215.176.110|20130114093453|20140114094336|523|20140114101001|9270|1799|359414536|2339687199|59|46600g0W|70|1|internet@internet.mtsindia.in|32852
9136713486|2|405891614985516|180.215.176.110|20130911093509|20140114093509|0|20140114101001|0|416|1157627956|16384|59|46600g0W|70|1|internet@internet.mtsindia.in|32852
9

ACTFILE:
Code:
8104665534|1903726104|1|8182|935674|MB|20140106|2
9136713486|1903743569|1|8182|936308|MB|20140101|6

DEACTFILE:
Code:
8104665534|1903739454|1|8453|185670|MB|20131214|8
9136713486|1903713493|1|8453|151012|MB|20130215|8

Present Code which only does replacement based on $1 checking and not on $5(date field) of ipfile:
Code:
awk -F"|" 'FNR==1 {++counter}
counter==1 {ACTFILE[$1]=$2"|"$3"|"$4"|"$5"|"$6;next}
counter==2 {DEACTFILE[$1]=$2"|"$3"|"$4"|"$5"|"$6;next}
{
if ( $1 in ACTFILE)
print ACTFILE[$1],$8,$9+$10> "ok.txt"
else if ( $1 in DEACTFILE)
print DEACTFILE[$1],$8,$9+$10> "nok.txt"
}
' FS="|" OFS="|" ACTFILE DEACTFILE IPFILE


Please help as i am unable to put the date field checks in the code.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

String Comparison between two files using awk

I have two files with field seperator as "~". File A: 12~13~14~15 File B: 22~22~32~11 i want to calculate the difference between two files and than calculate the percentage difference and output it to a new file. How do i do this using awk. Also please suggest GOOD awk tutorials. Thank... (7 Replies)
Discussion started by: rudoraj
7 Replies

2. Shell Programming and Scripting

Comparison of two files in awk

Hi, I have two files file1 and file2 delimited by semicolon, And I want to compare column 2 and column3 of file1 to column3 and column 4 in file2. file1 -------- abc;cef;155.67;143_34; def;fgh;146.55;123.3; frg;hff;134.67;; yyy;fgh;134.78;35_45; file 2 --------- abc;cef;155.09;;... (12 Replies)
Discussion started by: jerome Sukumar
12 Replies

3. Shell Programming and Scripting

Awk Comparison of 2 specific files

Hi Everybody, I know the topic sounds familiar but I just couldn't adapt or find the right code that solves my particular issue. I really hope you can help. I would like to compare 2 files in an awk script. Both files have different paths. The awk script call should look like that awk -f... (7 Replies)
Discussion started by: hhoosscchhii
7 Replies

4. Shell Programming and Scripting

Diff between 2 files using awk

Hi Experts, Could you please help me to find the difference between two files. I tried the diff command but did not like the output as it contained < and > signs and the line numbers. Is it possible to do something using awk? I have two files, say File1.txt contains 5 values and File2.txt... (6 Replies)
Discussion started by: forumthreads
6 Replies

5. Shell Programming and Scripting

Comparison and editing of files using awk.(And also a possible bug in awk for loop?)

I have two files which I would like to compare and then manipulate in a way. File1: pictures.txt 1.1 1.3 dance.txt 1.2 1.4 treehouse.txt 1.3 1.5 File2: pictures.txt 1.5 ref2313 1.4 ref2345 1.3 ref5432 1.2 ref4244 dance.txt 1.6 ref2342 1.5 ref2352 1.4 ref0695 1.3 ref5738 1.2... (1 Reply)
Discussion started by: linuxkid
1 Replies

6. UNIX for Dummies Questions & Answers

df -> output files; comparison using awk or...

:wall: I am trying to do the following using awk (is that the best way?): Read 2 files created from the output of df (say, on different days) and compare the entries using the 1st (FileSys) and 6th (Mount) fields to see if the size has changed. Output (at least), to a new file (some header... (2 Replies)
Discussion started by: renata
2 Replies

7. Shell Programming and Scripting

Show the diff in two files using awk

Hi, How can i use AWK or any other commands to find the difference between 2 files. File A aaa bbb ccc 111 222 File B aaa ccc 111 Output bbb 222 (6 Replies)
Discussion started by: gambit97
6 Replies

8. Shell Programming and Scripting

comparison of 2 files using unix or awk

Hello, I have 2 files and I want them to be compared in a specific fashion file1: A_1200_1250 A_1251_1300 B_1301_1350 B_1351_1400 B_1401_1450 C_1451_1500 and so on... file2: 1210 1305 1260 1295 1400 1500 1450 1495 Now The script should look for "1200" from A_1200_1250 of... (8 Replies)
Discussion started by: Diya123
8 Replies

9. UNIX for Dummies Questions & Answers

diff then awk two files

Hi friends, i am trying to diff two files and the result will be passed to awk and this will get the first 20 characters in every line and put the result in a file.... but i can't generate an output. $ cat file1.txt 1 2 3 4 5 $ cat file2.txt 1 2 3 4 the line of command is: (2 Replies)
Discussion started by: kokoro
2 Replies

10. UNIX for Beginners Questions & Answers

awk comparison using multiple files

Hi, I have 2 files, I need to use column of file1 and do a comparison on file2 column 1 and print the mismatch is file3 as mentioned below. Kindly consider that file 1 is having uniq key(column) whereas in file2 we have multiple duplicates (like 44). These duplicates should not come in... (2 Replies)
Discussion started by: grv
2 Replies
SORTM(1)							     [nmh-1.5]								  SORTM(1)

NAME
sortm - sort messages SYNOPSIS
sortm [+folder] [msgs] [-datefield field] [-textfield field] [-notextfield] [-limit days] [-nolimit] [-verbose | -noverbose] [-version] [-help] DESCRIPTION
Sortm sorts the specified messages in the named folder according to the chronological order of the "Date:" field of each message. The -verbose switch directs sortm to tell the user the general actions that it is taking to place the folder in sorted order. The -datefield field switch tells sortm the name of the field to use when making the date comparison. If the user has a special field in each message, such as "BB-Posted:" or "Delivery-Date:", then the -datefield switch can be used to direct sortm which field to examine. The -textfield field switch causes sortm to sort messages by the specified text field. If this field is "subject", any leading "re:" is stripped off. In any case, all characters except letters and numbers are stripped and the resulting strings are sorted datefield-major, textfield-minor, using a case insensitive comparison. With -textfield field, if -limit days is specified, messages with similar textfields that are dated within `days' of each other appear together. Specifying -nolimit makes the limit infinity. With -limit 0, the sort is instead made textfield-major, date-minor. For example, to order a folder by date-major, subject-minor, use: sortm -textfield subject +folder FILES
$HOME/.mh_profile The user profile PROFILE COMPONENTS
Path: To determine the user's nmh directory Current-Folder: To find the default current folder SEE ALSO
folder(1) DEFAULTS
`+folder' defaults to the current folder `msgs"'defaultstoall" `-datefield' defaults to date `-notextfield' `-noverbose' `-nolimit' CONTEXT
If a folder is given, it will become the current folder. If the current message is moved, sortm will preserve its status as current. HISTORY
Timezones used to be ignored when comparing dates: they aren't any more. Messages which were in the folder, but not specified by `msgs', used to be moved to the end of the folder; now such messages are left untouched. Sortm sometimes did not preserve the message numbering in a folder (e.g., messages 1, 3, and 5, might have been renumbered to 1, 2, 3 after sorting). This was a bug, and has been fixed. To compress the message numbering in a folder, use "folder -pack" as always. BUGS
If sortm encounters a message without a date-field, or if the message has a date-field that sortm cannot parse, then sortm attempts to keep the message in the same relative position. This does not always work. For instance, if the first message encountered lacks a date which can be parsed, then it will usually be placed at the end of the messages being sorted. When sortm complains about a message which it can't temporally order, it complains about the message number prior to sorting. It should indicate what the message number will be after sorting. MH.6.8 11 June 2012 SORTM(1)
All times are GMT -4. The time now is 12:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy