Sponsored Content
Top Forums Shell Programming and Scripting Keep the last instance of the record Post 302365630 by Scrutinizer on Tuesday 27th of October 2009 04:02:09 PM
Old 10-27-2009
Code:
$ awk -F '|' '{A[$1]=$2}END{for (i in A) print i"|"A[i]}' infile
1| abcde
2| abcd
3| abcde

This is using your example infile. If the last record would be 2 |abcde then the output is:
Code:
1| abcde
2| abcde

The input does not need to be sorted.

Last edited by Scrutinizer; 10-27-2009 at 05:08 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

splitting a record and adding a record to a file

Hi, I am new to UNIX scripting and woiuld appreicate your help... Input file contains only one (but long) record: aaaaabbbbbcccccddddd..... Desired file: NEW RECORD #new record (hardcoded) added as first record - its length is irrelevant# aaaaa bbbbb ccccc ddddd ... ... ... (1 Reply)
Discussion started by: rsolap
1 Replies

2. Shell Programming and Scripting

replace first instance(not first instance in line)

Alright, I think I know what I am doing with sed(which probably means I don't). But I cant figure out how to replace just the first occurance of a string. I have tried sed, ed, and grep but can't seem to figure it out. If you have any suggestions I am open to anything! (3 Replies)
Discussion started by: IronHorse7
3 Replies

3. UNIX for Dummies Questions & Answers

how to read record by record from a file in unix

Hi guys, i have a big file with the following format.This includes header(H),detail(D) and trailer(T) information in the file.My problem is i have to search for the character "6h" at 14 th and 15 th position in all the records .if it is there i have to write all those records into a... (1 Reply)
Discussion started by: raoscb
1 Replies

4. UNIX for Advanced & Expert Users

Print Full record and substring in that record

I have i got a requirement like below. I have input file which contains following fixed width records. 00000000000088500232007112007111 I need the full record and concatenated with ~ and characters from 1to 5 and concatenated with ~ and charactes from 10 to 15 The out put will be like... (1 Reply)
Discussion started by: ukatru
1 Replies

5. Shell Programming and Scripting

Reject the record if the record in the next line does not satisfy the pattern

Hi, I have a input file with the following entries: 1one 2two 3three 1four 2five 3six 1seven 1eight 1nine 2ten The output should be 1one 2two 3three 1four 2five 3six (2 Replies)
Discussion started by: supchand
2 Replies

6. Shell Programming and Scripting

Reject the record if the record in the next line does not begin with 2.

Hi, I have a input file with the following entries: 1one 2two 3three 1four 2five 3six 1seven 1eight 1nine 2ten 2eleven 2twelve 1thirteen 2fourteen The output should be: (5 Replies)
Discussion started by: supchand
5 Replies

7. Shell Programming and Scripting

How to compare current record,with next and previous record in awk without using array?

Hi! all can any one tell me how to compare current record of column with next and previous record in awk without using array my case is like this input.txt 0 32 1 26 2 27 3 34 4 26 5 25 6 24 9 23 0 32 1 28 2 15 3 26 4 24 (7 Replies)
Discussion started by: Dona Clara
7 Replies

8. Shell Programming and Scripting

Extract timestamp from first record in xml file and it checks if not it will replace first record

I have test.xml <emp><id>101</id><name>AAA</name><date>06/06/14 1811</date></emp> <Join><id>101</id><city>london</city><date>06/06/14 2011</date></join> <Join><id>101</id><city>new york</city><date>06/06/14 1811</date></join> <Join><id>101</id><city>sydney</city><date>06/06/14... (2 Replies)
Discussion started by: vsraju
2 Replies

9. Shell Programming and Scripting

Replace a string for every record after the 1st record

I have data coming in the below format for each record <?xml version="1.0" encoding="UTF-8" standalone="no"?><test_sox xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><testdetials>....</test_sox> <?xml version="1.0" encoding="UTF-8" standalone="no"?><test_sox... (8 Replies)
Discussion started by: dsravanam
8 Replies

10. Shell Programming and Scripting

Need code for updating second record to first record in shell scripting

Hi,, I have requirement that i need to get DISTINCT values from a table and if there are two records i need to update it to one record and then need to submit INSERT statements by using the updated value as a parameter. Here is the example follows.. SELECT DISTINCT ID FROM OFFER_GROUP WHERE... (1 Reply)
Discussion started by: Samah
1 Replies
makedbm(1M)															       makedbm(1M)

NAME
makedbm - make a Network Information System database SYNOPSIS
nis_input_file] nis_output_name] nis_domain_name] nis_master_name] infile outfile database_name Remarks The Network Information Service (NIS) was formerly known as Yellow Pages (yp). Although the name has changed, the functionality of the service remains the same. DESCRIPTION
generates databases (maps) for the Network Information System (NIS) from infile. A database created by consists of two files: and A data- base contains records called dbm records composed of key-value pairs. Each line of infile is converted to a single dbm record; all characters up to the first tab or space form the key, and the remainder of the line is the value. If a value read from infile ends with the value for that record is continued onto the next line. The NIS clients must interpret the character (which means that does not treat the as if it precedes a comment). If infile is a hyphen reads standard input. always generates a special dbm record with the key whose value is the time of last modification of infile (or the current time, if infile is This value is also known as the order number of a map, and prints it for a specified NIS map (see yppoll(1M)). Another special dbm record created by has the key Its value is usually the host name retrieved by however, the option can be used to spec- ify a different value (see gethostname(2)). If the option is used, another special dbm record with the key is created. When this key exists in the NIS host.by* maps or ipnodes.by* maps and the NIS host name resolution fails, the process will query the Internet domain name server, to provide the host name resolution. Before using the option, it is recommended that the name services switch, be set to allow NIS host name resolution first. (Note that, since the process only checks hosts.by* and ipnodes.by* for the existence of the key, using the option on any other NIS map will have no effect. Also, the option should be used on both the *.byname and *.byaddr maps, not one exclusively.) If the option is used, another special dbm record created is the key. If this key exists in an NIS map, will only allow privileged pro- cesses (applications that can create reserved ports) to access the data within the map. Options recognizes the following options and command-line arguments. Create a special dbm record with the key This key, which is in the hosts.byname, hosts.byaddr, ipnodes.byname, and ipnodes.byaddr maps, allows the process to query the Internet domain name server (see named(1M)). Convert the keys of the given map to lowercase. This command option allows host name matches to work independent of character-case distinctions. Accept connections from secure NIS networks only. Create a special dbm record with the key and the value If the option is used, another special dbm record created is the key. If this key exists in an NIS map, will only allow privileged processes to access the data within the map (that is, applications that can create reserved ports). Create a special dbm record with the key and the value nis_output_name. Create a special dbm record with the key and the value nis_domain_name. Replace the value of the special dbm record whose key is with nis_master_name. Undo the database_name (that is, write the contents of database_name to the standard output) one dbm record per line. A single space sepa- rates each key from its value. EXAMPLES
Shell scripts can be written to convert ASCII files such as to the key-value form used by For example, #!/usr/bin/sh /usr/bin/awk 'BEGIN { FS = ":" } { print $1, $0 }' /etc/netgroup | makedbm - netgroup converts the file to a form that is read by to make the NIS map The keys in the database are names, and the values are the remainders of the lines in the file. AUTHOR
was developed by Sun Microsystems, Inc. SEE ALSO
domainname(1), named(1M), ypinit(1M), ypmake(1M), yppoll(1M), gethostname(2), netgroup(4), ypfiles(4). makedbm(1M)
All times are GMT -4. The time now is 09:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy