Hi Ravinder,
I think you understand what it is doing. Here is a different way to comment the code that takes more lines to describe, but fits in an 80 column screen:
Code:
awk '
BEGIN { # Set input and output field separators to a tab.
FS = OFS = "\t"
# Initialize the table of fields to process (fields[]) and increment the
# number of Lookup files to expect (nf).
fields[++nf] = 2 # The 1st Lookup file translates field #2.
fields[++nf] = 3 # The next Lookup file translates field #3.
fields[++nf] = 4 # The next Lookup file translates field #4.
}
# If this is the 1st line in a file...
FNR == 1 {
# increment the input file number.
f++
}
# If we are looking at a line from a Lookup file...
f <= nf {
# set the lookup table (l[]) entry for this file (f) and input value
# ($1) to the corresponding subfield data to be added ($2).
l[f, $1] = $2
# Skip to next input line and do not perform the following actions...
next
}
# If we get to this point, we have read and accumulated data from all of the
# Lookup files and are now looking at a line from our data file.
{ # Process each field in our table of fields (starting with the last
# field first). Note that when we add a tab to a field, the field
# numbers of following fields will change.
for(i = nf; i > 0; i--) {
# Split the selected field into subfields (sf[]) and get the
# number of subfields to process (n).
n = split($fields[i], sf, " ")
# Set the initial contents of the added field data to the output
# field separator.
af = OFS
# For each subfield in this field, append the lookup table value
# for the entry in the Lookup file corresponding to this field
# and subfield value, and follow each converted subfield value
# with a space (for the 1st n-1 subfields) or by nothing (for
# the lsat subfield).
for(j = 1; j <= n; j++)
af = af l[i, sf[j]] ((j < n) ? " " : "")
# Append the accumulated looked up data to the current field
# contents.
$fields[i] = $fields[i] af
}
}
1 # Print the updated contents of the current data file line.
' Lookup2 Lookup3 Lookup4 file # Specify the Lookup files and the data file to
# be processed.
These 2 Users Gave Thanks to Don Cragun For This Post:
Using AIX 5.2, Bourne and Korn Shell.
I have two flat text files. One is a main file and one is a lookup table that contains a number of letter codes and membership numbers as follows:
316707965EGM01
315672908ANM92
Whenever one of these records from the lookup appears in the main file... (6 Replies)
I am trying to transpose tables listed in the format into format. Any help would be greatly appreciated.
Input:
test_data_1
1 2 90%
4 3 91%
5 4 90%
6 5 90%
9 6 90%
test_data_2
3 5 92%
5 4 92%
7 3 93%
9 2 92%
1 1 92%
...
Output:... (7 Replies)
Hi All
I have got a fixed length file of 80bytes long.The first 4bytes of each record represents a client_number.I need to modify the client number based on another lookup file.
The lookup file contains 2 fields and a comma delimited file.The first line of the lookup file contains the header... (5 Replies)
Write a quick shell snippet to find all of the IPV4 IP addresses
in any and all of the files under /var/lib/output/*, ignoring
whatever else may be in those files. Perform a reverse lookup on
each, and format the output neatly, like "IP=192.168.0.1,
... (0 Replies)
hey guys,
can anybody help me out here on the following:
grep '^\{1,3\}\.\{1,3\}\.\{1,3\}\.\{1,3\}$' ravi.txt mary.txt lisa.txt https://www.unix.com/images/misc/progress.gif
i.e what i did was found ip addreses from different files
and then i want... (1 Reply)
I have a lookup file in unix say /data/lkp.dat (First line is header and space delimited) and the content is shown below.
Another file which contains the job_name and rec_count lets say /data/data_file.dat(no header pipe delimited file).
Now i want to do a lookup on job_name and my output should... (3 Replies)
To give you some context of my issue the following is some sample dummy data. The field delimiter is "<-->". The 4th field is going to be tags for my notes. The tags should always be unique and sorted alphabetically.
1<-->01/20/12<-->01/20/12<-->1st note<-->1st note<-NL->2 lines... (4 Replies)
hello masters,
I am working with csv files that open just fine in excel, but have sub-fields which are comma separated as well.
a 3 column csv looks like
a,b,"c,d,e"
f,g,h
How do I make join or sort believe that "c,d,e" is just 1 field? (8 Replies)
Hello experts,
I have a file looking like
v1 g1 5.42
v2 g1 2.43
v1 g2 1.24
v3 g2 0.6
I want to lookup the first value in another sorted table which is greater than column 3 value, keying on column 2 on the first table.
The sorted table looks like the following,. where I want to find... (3 Replies)
Discussion started by: sheetalk
3 Replies
LEARN ABOUT DEBIAN
mdb-tables
MDBTools(1)MDBTools(1)NAME
mdb-tables - Get listing of tables in an MDB database
SYNOPSIS
mdb-tables [-S] [-1 | -d delimiter] database
DESCRIPTION
mdb-tables is a utility program distributed with MDB Tools.
It produces a list of tables contained within an MDB database in a format suitable for use in shell scripts.
OPTIONS -S Show system tables. System tables are generally those beginning with 'MSys'
-1 specifies that the tables should be listed 1 per line.
-d delimiter
specifies an alternative delimiter. If no delimiter is specified, table names will be delimited by a tab character, or by newline if
the -1 option was specified.
NOTES ENVIRONMENT
MDB_JET3_CHARSET
Defines the charset of the input JET3 (access 97) file. Default is CP1252. See iconv(1).
MDBICONV
Defines the output charset. Default is UTF-8. mdbtools must have been compiled with iconv.
MDBOPTS
semi-column separated list of options:
o use_index
o no_memo
o debug_like
o debug_write
o debug_usage
o debug_ole
o debug_row
o debug_props
o debug_all is a shortcut for all debug_* options
HISTORY
mdb-tables first appeared in MDB Tools 0.3.
SEE ALSO gmdb2(1)mdb-export(1)mdb-hexdump(1)mdb-prop(1)mdb-sql(1)mdb-ver(1)mdb-array(1)mdb-header(1)mdb-parsecsv(1)mdb-schema(1)AUTHORS
The mdb-tables utility was written by Brian Bruns.
BUGS
Access allows for tables to have spaces embeded in the table name.
You must specify a delimiter (-d) if you intend on piping the output of mdb-tables to a program such as awk or cut.
0.7 13 July 2013 MDBTools(1)