Sponsored Content
Top Forums Shell Programming and Scripting Remove duplicated records and update last line record counts Post 303032040 by Don Cragun on Sunday 10th of March 2019 01:37:35 AM
Old 03-10-2019
Quote:
Originally Posted by nezabudka
Code:
awk -F, '/^T/ {for(i in A) sum+=(A[i]-1); $2=$2-sum} !A[$0]++' file

Hi nezabudka,
Nice approach. My code counts the number of lines output and ignores the value originally found in the "T" line field #2; your code subtracts the number of duplicates found.

If there were to be input files with multiple "T" lines, mine would output all of them each containing the number of unique "D" lines seen up to that point while yours will only print the first one found. I assume that an input file will only contain one "T" line, so this difference shouldn't matter.

If there are lines other than "D" and "T" lines, my code will copy them to the output but not include them in the count included in the "T" line; your code will include a count of non-duplicated non-"D" (except for the first "T" line) in its calculations. I have no idea whether or not the actual data to be processed might contain any header lines that should not be included in the in the "T" line output. If header lines are present and should be ignored in the "T" line output, that should have been mentioned in the requirements.

Note that your code replaces the commas in the "T" line output with <space>s because you didn't set OFS to a comma.
These 2 Users Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

remove duplicated xml record in a file under unix

Hi, If i have a file with xml format, i would like to remove duplicated records and save to a new file. Is it possible...to write script to do it? (8 Replies)
Discussion started by: happyv
8 Replies

2. Shell Programming and Scripting

remove duplicated columns

hi all, i have a file contain multicolumns, this file is sorted by col2 and col3. i want to remove the duplicated columns if the col2 and col3 are the same in another line. example fileA AA BB CC DD CC XX CC DD BB CC ZZ FF DD FF HH HH the output is AA BB CC DD BB CC ZZ FF... (6 Replies)
Discussion started by: kamel.seg
6 Replies

3. Shell Programming and Scripting

Help to Add and Remove Records only from first line/last line

Hi, I need help with a maybe total simple issue but somehow I am not getting it. I am not able to etablish a sed or awk command which is adding to the first line in a text and removing only from the last line the ",". The file is looking like follow: TABLE1, TABLE2, . . . TABLE99,... (4 Replies)
Discussion started by: enjoy
4 Replies

4. Shell Programming and Scripting

Sending e-mail of record counts in 3 or more files

I am trying to load data into 3 tables simultaneously (which is working fine). Then when loaded, it should count the total number of records in all the 3 input files and send an e-mail to the user. The script is working fine, as far as loading all the 3 input files into the database tables, but... (3 Replies)
Discussion started by: msrahman
3 Replies

5. Shell Programming and Scripting

Split a single record to multiple records & add folder name to each line

Hi Gurus, I need to cut single record in the file(asdf) to multile records based on the number of bytes..(44 characters). So every record will have 44 characters. All the records should be in the same file..to each of these lines I need to add the folder(<date>) name. I have a dir. in which... (20 Replies)
Discussion started by: ram2581
20 Replies

6. UNIX for Dummies Questions & Answers

Hardcoding & Record counts in a file

HI , I am having a huge comma delimiter file, I have to append the following four lines before the starting of the file through a shell script. FILE NAME = TEST_LOAD DATETIME = CURRENT DATE TIME LOAD DATE = CURRENT DATE RECORD COUNT = TOTAL RECORDS IN FILE Source data 1,2,3,4,5,6,7... (7 Replies)
Discussion started by: shruthidwh
7 Replies

7. Shell Programming and Scripting

New file should store all the 7 existing filenames and their record counts and ftp th

Hi, I need help regarding below concern. There is a script and it has 7 existing files(in a path say,. usr/appl/temp/file1.txt) and I need to create one new blank file say “file_count.txt” in the same script itself. Then the new file <file_count.txt> should store all the 7 filenames and... (1 Reply)
Discussion started by: pr293
1 Replies

8. Shell Programming and Scripting

How to Remove the new line character inbetween a record

I have a file, in which a single record spans across multiple lines, File 1 ==== 14|\n leave request \n accepted|Yes| 15|\n leave request not \n acccepted|No| I wanted to remove the '\n charecters. I used the below code (foudn somewhere in this forum) perl -e 'while (<>) { if... (1 Reply)
Discussion started by: machomaddy
1 Replies

9. Shell Programming and Scripting

How to remove duplicated lines?

Hi, if i have a file like this: Query=1 a a b c c c d Query=2 b b b c c e . . . (7 Replies)
Discussion started by: the_simpsons
7 Replies

10. Shell Programming and Scripting

Join files, omit duplicated records from one file

Hello I have 2 files, eg more file1 file2 :::::::::::::: file1 :::::::::::::: 1 fromfile1 2 fromfile1 3 fromfile1 4 fromfile1 5 fromfile1 6 fromfile1 7 fromfile1 :::::::::::::: file2 :::::::::::::: 3 fromfile2 5 fromfile2 (4 Replies)
Discussion started by: CHoggarth
4 Replies
TCRMGR(1)							   Tokyo Tyrant 							 TCRMGR(1)

NAME
tcrmgr - the command line utility of the remote database API DESCRIPTION
The command `tcrmgr' is a utility for test and debugging of the remote database API and its applications. `host' specifies the host name of the server. `key' specifies the key of a record. `value' specifies the value of a record. `params' specifies the tuning parameters. `dpath' specifies the destination file. `func specifies the name of the function. `arg' specifies the arguments of the function. `file' specifies the input file. `upath' specifies the update log directory. `mhost' specifies the host name of the replication master. `url' specifies the target URL. tcrmgr inform [-port num] [-st] host Print miscellaneous information to the standard output. tcrmgr put [-port num] [-sx] [-sep chr] [-dk|-dc|-dai|-dad] host key value Store a record. tcrmgr out [-port num] [-sx] [-sep chr] host key Remove a record. tcrmgr get [-port num] [-sx] [-sep chr] [-px] [-pz] host key Print the value of a record. tcrmgr mget [-port num] [-sx] [-sep chr] [-px] host [key...] Print keys and values of multiple records. tcrmgr list [-port num] [-sep chr] [-m num] [-pv] [-px] [-fm str] host Print keys of all records, separated by line feeds. tcrmgr ext [-port num] [-xlr|-xlg] [-sx] [-sep chr] [-px] host func [key [value]] Call a script language extension function. tcrmgr sync [-port num] host Synchronize updated contents with the database file. tcrmgr optimize [-port num] host [params] Optimize the database file. tcrmgr vanish [-port num] host Remove all records. tcrmgr copy [-port num] host dpath Copy the database file. tcrmgr misc [-port num] [-mnu] [-sx] [-sep chr] [-px] host func [arg...] Call a versatile function for miscellaneous operations. tcrmgr importtsv [-port num] [-nr] [-sc] host [file] Store records of TSV in each line of a file. tcrmgr restore [-port num] [-ts num] [-rcc] host upath Restore the database with update log. tcrmgr setmst [-port num] [-mport num] [-ts num] [-rcc] host [mhost] Set the replication master. tcrmgr repl [-port num] [-ts num] [-sid num] [-ph] host Replicate the update log. tcrmgr http [-ah name value] [-ih] url Fetch the resource of a URL by HTTP. tcrmgr version Print the version information of Tokyo Tyrant. Options feature the following. -port num : specify the port number. -st : print miscellaneous status data. -sx : input data is evaluated as a hexadecimal data string. -sep chr : specify the separator of the input data. -dk : use the function `tcrdbputkeep' instead of `tcrdbput'. -dc : use the function `tcrdbputcat' instead of `tcrdbput'. -dai : use the function `tcrdbaddint' instead of `tcrdbput'. -dad : use the function `tcrdbadddouble' instead of `tcrdbput'. -px : output data is converted into a hexadecimal data string. -pz : do not append line feed at the end of the output. -m num : specify the maximum number of the output. -pv : print values of records also. -fm str : specify the prefix of keys. -xlr : perform record locking. -xlg : perform global locking. -mnu : omit the update log. -nr : use the function `tcrdbputnr' instead of `tcrdbput'. -sc : normalize keys as lower cases. -mport num : specify the port number of the replication master. -ts num : specify the beginning time stamp. -rcc : check consistency of replication. -sid num : specify the self server ID. -ph : print human-readable data. -ah name value : add a request header. -ih : output response headers also. If the port number is not more than 0, UNIX domain socket is used and the path of the socket file is specified by the host parameter. This command returns 0 on success, another on failure. SEE ALSO
ttserver(1), ttultest(1), ttulmgr(1), tcrtest(1), tcrmttest(1), ttutil(3), tcrdb(3) Man Page 2010-01-20 TCRMGR(1)
All times are GMT -4. The time now is 01:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy