Sponsored Content
Top Forums Shell Programming and Scripting Need awk script to compare 2 fields in fixed length file. Post 302347444 by Muga801 on Tuesday 25th of August 2009 05:10:26 PM
Old 08-25-2009
Need awk script to compare 2 fields in fixed length file.

Need a script that manipulates a fixed length file that will compare 2 fields in that file and if they are equal write that line to a new file.

i.e. If fields 87-93 = fields 119-125, then write the entire line to a new file. Do this for every line in the file. After we get only the fields that have duplicates in a separate file, take that file and look in field 83, if it equals 66 or 88 then delete that line and save to a new file.

I would prefer not to do this in Perl, not many people in this office use or understand Perl. The files format is something like this:

Code:
6ZDA90603C5559518898683765109438327630000100000002132P008377612{22004020AZ 07332  195572A2008101645781015365999999SWZSHINABFMN                              PZTENNBD                    F                                  281808023Z19721202  365944281 00354299505F85323          CC0501AB            000900000000{  7242                                            2001A{{0000002132P00000000{0000000000{0000002132P0000000000{0000000000{0000000000{3{2004622008110109WC0725200810170830009031                                                       2008110320081103O001200401062004010699245                   00{00000000{00002132P00000000{NW0000{00000000{C00002132PA1                       AZ 270036484A01785306    207L00000XY1270036484    22O3R03MO   BZ 108  V       00                  0   E 03O00105
8WGB90603C000951889962167553050300000007900000234481K000000000{22007078AZ 97698  14084052008103120081024601502995SAZPERRY                              FRGWQFTY                                                     000066760S19760301  112321919400735900702F85613    F     AH0301AA            000800000000{  7244                                            2003A{{0000007854E00000000{0000007350{0000002607E0000000000{0000000000{0000000000{1A2004622008110109WC0725200811030860785028                                                       2007032176431103I00120040422200404229590059                 00D00002840{00000534E00000000{NW0000{00000000{B00000534E42                       AZ 860566486L00285635    2084N0400XY1             11O1A05ZZ   BZ 108WCW       00                  1 01E   O04113
6MDA90603C000951889962120083050300000007900000234481K000000000{22007078AZ 97698  14084053467103120081024601502995SAZPERRY                              MAINE                                                     785633760S19760301  112321919400735900702F85613    F     AH0301AA            000800000000{  7244                                            1822A{{0000002607E00000000{0022007350{0000002607E0468300000{0000000000{0000000000{1A2004622008110109WC0725200811030860785028                                                       2007032112541103I002200404222004042295904                   00D99992680{00001703{00000000{NW0000{67800000{B00001703{42                       AZ 860566486L00285635    2084N0400XY1             11O1A05ME   BZ 108WCW       00                  1 01E   O04013


Last edited by vgersh99; 08-25-2009 at 06:12 PM.. Reason: code tags, PLEASE!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

fixed length fields in awk

I am trying to display df -h command out in proper format, how can I display each field of each record in a fixed length. (2 Replies)
Discussion started by: roopla
2 Replies

2. Shell Programming and Scripting

Awk with fixed length files

Hi Unix Champs, I want to awk on a fixed length file. Instead if the file was a delimited file, then I could have used -F and then could have easily done manipulation on the fields. How do i do the same in case of fixed length file? Thanks in Advance. Regards. (7 Replies)
Discussion started by: c2b2
7 Replies

3. Shell Programming and Scripting

Awk - Working with fixed length files

OK I am somewhat new to UNIX programming please see what you can do to help. I have a flat file that is a fixed length file containing different records based on the 1st character of each line. The 1st number at the beginning of the line is the record number, in this case it's record #1. I... (3 Replies)
Discussion started by: ambroze
3 Replies

4. UNIX for Dummies Questions & Answers

What the command to find out the record length of a fixed length file?

I want to find out the record length of a fixed length file? I forgot the command. Any body know? (9 Replies)
Discussion started by: tranq01
9 Replies

5. UNIX for Dummies Questions & Answers

Convert a tab delimited/variable length file to fixed length file

Hi, all. I need to convert a file tab delimited/variable length file in AIX to a fixed lenght file delimited by spaces. This is the input file: 10200002<tab>US$ COM<tab>16/12/2008<tab>2,3775<tab>2,3783 19300978<tab>EURO<tab>16/12/2008<tab>3,28523<tab>3,28657 And this is the expected... (2 Replies)
Discussion started by: Everton_Silveir
2 Replies

6. Shell Programming and Scripting

Fixed length fields

HPUX and posix shell Hi all. I have a record with fixed length fields....I would like to reorder the fields and preserver the fixed lengths.... cat test 4 960025460 Dept of Music 8 960025248 Dept of Music 12-08 cat... (3 Replies)
Discussion started by: lyoncc
3 Replies

7. Shell Programming and Scripting

awk to print fixed length columns to right side

Hi, I am in a situation to print the message on a column, where the each line starting position should be same. For example code: HOSTNAME1="1.2.3.4.5.6.7" TARGET_DIR="/tmp" echo "HOSTNAME1:" "$HOSTNAME1" | awk -v var="Everyone" '{len=55-length;printf("%s%*s\n",$0,len,var)}' echo... (4 Replies)
Discussion started by: tprabhaker
4 Replies

8. Shell Programming and Scripting

Splitting fixed length file using awk

Hi, I need to split a fixed length file of 160 characters based on value of a column. Example: ABC 456780001 DGDG SDFSF BCD 444440002 SSSS TTTTT ABC 777750003 HHHH UUUUU THH 888880001 FFFF LLLLLL HHH 999990002 GGGG OOOOO I need to split this file on basis of column from... (7 Replies)
Discussion started by: Neelkanth
7 Replies

9. Shell Programming and Scripting

Fixed Length file from a SQL script

Hi, I have a DB2 UDB 9.7 SQL script, as follows: I need to pass the script into Unix and generate a fixed length file from this. Can someone kindly provide a script to achieve it? SELECT CAST(COALESCE(CL_ID,'000000000') AS CHAR(9)) AS CL_ID ,STATUS... (5 Replies)
Discussion started by: ebsus
5 Replies

10. UNIX for Beginners Questions & Answers

Splitting the file based on two fields - Fixed length file

Hi , I am having a scenario where I need to split the file based on two field values. The file is a fixed length file. ex: AA0998703000000000000190510095350019500010005101980301 K 0998703000000000000190510095351019500020005101480 ... (4 Replies)
Discussion started by: saj
4 Replies
ACTIVE(5)						    InterNetNews Documentation							 ACTIVE(5)

NAME
active - List of newsgroups carried by the server DESCRIPTION
The file pathdb/active lists the newsgroups carried by INN. This file is generally maintained using ctlinnd(8) to create and remove groups, or by letting controlchan(8) do so on the basis of received control messages; this file is then updated and a backup stored in pathdb/active.old. Note that the newsgroups(5) file normally contains the descriptions of the newsgroups carried by the news server. The active file should not be edited directly without throttling innd, and must be reloaded using ctlinnd before innd is unthrottled. Editing it directly even with those precautions may make it inconsistent with the overview database and won't update active.times, so ctlinnd should be used to make modifications whenever possible. Each newsgroup should be listed only once. Each line specifies one group. The order of groups does not matter. Within each newsgroup, received articles for that group are assigned monotonically increasing numbers as unique names. If an article is posted to newsgroups not mentioned in this file, those newsgroups are ignored. If none of the newsgroups listed in the Newsgroups: header of an article are present in this file, the article is either rejected (if wanttrash is false in inn.conf), or is filed into the newsgroup "junk" and, when "Aj" is not set in the newsfeeds feed pattern, only propagated to sites that receive the "junk" newsgroup (if wanttrash is true). Each line of this file consists of four fields separated by a space: <name> <high> <low> <status> The first field is the name of the newsgroup. The newsgroup "junk" is special, as mentioned above. The newsgroup "control" and any newsgroups beginning with "control." are also special; control messages are filed into a control.* newsgroup named after the type of control message if that group exists, and otherwise are filed into the newsgroup "control" (without regard to what newsgroups are listed in the Newsgroups: header). If mergetogroups is set to true in inn.conf, newsgroups that begin with "to." are also treated specially; see innd(8). The second field is the highest article number that has been used in that newsgroup. The third field is the lowest article number in the group; this number is not guaranteed to be accurate, and should only be taken to be a hint. It is normally updated nightly as part of the expire process; see news.daily(8) and look for "lowmark" or "renumber" for more details. Note that because of article cancellations, there may be gaps in the numbering sequence. If the lowest article number is greater than the highest article number, then there are no articles in the newsgroup. In order to make it possible to update an entry in-place without rewriting the entire file, the second and third fields are padded out with leading zeros to make them a fixed width. The fourth field contains one of the following status: y Local postings and articles from peers are allowed. m The group is moderated and all postings must be approved. n No local postings are allowed, only articles from peers. j Articles from peers are filed in the junk group instead. x No local postings, and articles from peers are ignored. =foo.bar Articles are filed in the group foo.bar instead. If a newsgroup has the "j" status, no articles will be filed in that newsgroup. Local postings are not accepted; if an article for that newsgroup is received from a remote site, and if it is not crossposted to some other valid group, it will be filed into the "junk" newsgroup instead. This is different than simply not listing the group, since the article will still be accepted and can be propagated to other sites, and the "junk" group can be made available to readers if wished. If the <status> field begins with an equal sign, the newsgroup is an alias. Articles cannot be posted to that newsgroup, but they can be received from other sites. Any articles received from peers for that newsgroup are treated as if they were actually posted to the group named after the equal sign. Note that the Newsgroups: header of the articles is not modified. (Alias groups are typically used during a transition and are typically created manually with ctlinnd(8).) An alias should not point to another alias. Note that readers.conf can be configured so that local posts to newsgroups with status "j", "n" or "x" are accepted. MINIMAL ACTIVE FILE
For innd to be able to start, the three groups "control", "control.cancel" and "junk" need to be in the active file. Besides, if mergetogroups is set to true in inn.conf, the newsgroup "to" also needs to exist. The minimal active file shipped with INN is: control 0000000000 0000000001 n control.cancel 0000000000 0000000001 n control.checkgroups 0000000000 0000000001 n control.newgroup 0000000000 0000000001 n control.rmgroup 0000000000 0000000001 n junk 0000000000 0000000001 n (Note that the second and the third field may differ if the news server has already been in use.) There are more control.* pseudogroups here than needed by innd to start; the corresponding control messages will be filed into them. The "n" status is so that users cannot post directly to these groups (control messages should only be posted to the groups that they affect). If you do not want these groups to be visible to clients, do not delete them but simply hide them in readers.conf(5). To create additional groups after the server is running, you can use "ctlinnd newgroup". You can also synchronize your newsgroup list to that of another server by using actsync(8) or get the active file of another NNTP server with getlist(1). And do not forget to update your newsgroups file, which can be automatically done thanks to docheckgroups called with the -u flag. HISTORY
Written by Rich $alz <rsalz@uunet.uu.net> for InterNetNews. Converted to POD by Russ Allbery <rra@stanford.edu>. $Id: active.pod 9031 2010-03-23 18:31:55Z iulius $ SEE ALSO
active.times(5), actsync(8), controlchan(8), ctlinnd(8), docheckgroups(8), getlist(1), inn.conf(5), innd(8), mod-active(8), news.daily(8), newsgroups(5), readers.conf(5). INN 2.5.2 2010-03-23 ACTIVE(5)
All times are GMT -4. The time now is 06:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy