Sponsored Content
Top Forums Shell Programming and Scripting finding duplicates in columns and removing lines Post 302189010 by in2nix4life on Thursday 24th of April 2008 04:44:07 PM
Old 04-24-2008
With the 'uniq' command:

uniq -1 [inputfile]

Hope this helps.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Removing lines that are (same in content) based on columns

I have a file which looks like AA BB CC DD EE FF GG HH KK AA BB GG HH KK FF CC DD EE AA BB CC DD EE UU VV XX ZZ AA BB VV XX ZZ UU CC DD EE .... I want the script to give me only one line based on duplicate contents: AA BB CC DD EE FF GG HH KK AA BB CC DD EE UU VV XX ZZ (7 Replies)
Discussion started by: adsforall
7 Replies

2. Shell Programming and Scripting

Help removing lines with duplicated columns

Hi Guys... Please Could you help me with the following ? aaaa bbbb cccc sdsd aaaa bbbb cccc qwer as you can see, the 2 lines are matched in three fields... how can I delete this pupicate ? I mean to delete the second one if 3 fields were duplicated ? Thanks (14 Replies)
Discussion started by: yahyaaa
14 Replies

3. Shell Programming and Scripting

Finding duplicates from positioned substring across lines

I have million's of records each containing exactly 50 characters and have to check the uniqueness of 4 character substring of 50 character (postion known prior) and report if any duplicates are found. Eg. data... AAAA00000000000000XXXX0000 0000000000... upto50 chars... (2 Replies)
Discussion started by: gapprasath
2 Replies

4. Shell Programming and Scripting

Removing duplicates from string (not duplicate lines)

please help me in getting following: Input Desired output x="foo" foo x="foo foo" foo x="foo foo" foo x="foo abc foo" foo abc x="foo foo1 foo2" foo foo1 foo2 I need to remove duplicated from string.. (8 Replies)
Discussion started by: vickylife
8 Replies

5. Shell Programming and Scripting

finding duplicates in csv based on key columns

Hi team, I have 20 columns csv files. i want to find the duplicates in that file based on the column1 column10 column4 column6 coulnn8 coulunm2 . if those columns have same values . then it should be a duplicate record. can one help me on finding the duplicates, Thanks in advance. ... (2 Replies)
Discussion started by: baskivs
2 Replies

6. Shell Programming and Scripting

Help in removing duplicates

I have an input file abc.txt with info like: abcd rateuse inklite robet rateuse abcd I need to remove duplicates from the file (eg: abcd,rateuse) from the file and need to place the contents in same file abc.txt if needed can be placed in another file. can anyone help me in this :( (4 Replies)
Discussion started by: rkrish
4 Replies

7. Shell Programming and Scripting

Removing duplicates in fixed width file which has multiple key columns

Hi All , I have a requirement where I need to remove duplicates from a fixed width file which has multiple key columns .Also , need to capture the duplicate records into another file . File has 8 columns. Key columns are col1 and col2. Col1 has the length of 8 col 2 has the length of 3. ... (5 Replies)
Discussion started by: saj
5 Replies

8. Shell Programming and Scripting

UNIX scripting for finding duplicates and null records in pk columns

Hi, I have a requirement.for eg: i have a text file with pipe symbol as delimiter(|) with 4 columns a,b,c,d. Here a and b are primary key columns.. i want to process that file to find the duplicates and null values are in primary key columns(a,b) . I want to write the unique records in which... (5 Replies)
Discussion started by: praveenraj.1991
5 Replies

9. Shell Programming and Scripting

Removing duplicates from delimited file based on 2 columns

Hi guys,Got a bit of a bind I'm in. I'm looking to remove duplicates from a pipe delimited file, but do so based on 2 columns. Sounds easy enough, but here's the kicker... Column #1 is a simple ID, which is used to identify the duplicate. Once dups are identified, I need to only keep the one... (2 Replies)
Discussion started by: kevinprood
2 Replies

10. Shell Programming and Scripting

Removing carriage returns from multiple lines in multiple files of different number of columns

Hello Gurus, I have a multiple pipe separated files which have records going over multiple Lines. End of line separator is \n and records going over multiple lines have <CR> as separator. below is example from one file. 1|ABC DEF|100|10 2|PQ RS T|200|20 3| UVWXYZ|300|30 4| GHIJKL|400|40... (7 Replies)
Discussion started by: dJHa
7 Replies
TabularDisplay(3pm)					User Contributed Perl Documentation				       TabularDisplay(3pm)

NAME
Text::TabularDisplay - Display text in formatted table output SYNOPSIS
use Text::TabularDisplay; my $table = Text::TabularDisplay->new(@columns); $table->add(@row) while (@row = $sth->fetchrow); print $table->render; +----+--------------+ | id | name | +----+--------------+ | 1 | Tom | | 2 | Dick | | 3 | Barry | | | (aka Bazza) | | 4 | Harry | +----+--------------+ DESCRIPTION
Text::TabularDisplay simplifies displaying textual data in a table. The output is identical to the columnar display of query results in the mysql text monitor. For example, this data: 1, "Tom Jones", "(666) 555-1212" 2, "Barnaby Jones", "(666) 555-1213" 3, "Bridget Jones", "(666) 555-1214" Used like so: my $t = Text::TabularDisplay->new(qw(id name phone)); $t->add(1, "Tom Jones", "(666) 555-1212"); $t->add(2, "Barnaby Jones", "(666) 555-1213"); $t->add(3, "Bridget Jones", "(666) 555-1214"); print $t->render; Produces: +----+---------------+----------------+ | id | name | phone | +----+---------------+----------------+ | 1 | Tom Jones | (666) 555-1212 | | 2 | Barnaby Jones | (666) 555-1213 | | 3 | Bridget Jones | (666) 555-1214 | +----+---------------+----------------+ METHODS
Text::TabularDisplay has four primary methods: new(), columns(), add(), and render(). new() creates a new Text::TabularDisplay instance; columns() sets the column headers in the output table; add() adds data to the instance; and render() returns a formatted string representation of the instance. There are also a few auxiliary convenience methods: clone(), items(), reset(), populate(), and paginate(). new A Text::TabularDisplay instance can be created with column names passed as constructor args, so these two calls produce similar objects: my $t1 = Text::TabularDisplay->new; $t1->columns(qw< one two >); my $t2 = Text::TabularDisplay->new(qw< one two >); Calling new() on a Text::TabularDisplay instance returns a clone of the object. See "clone" in Text::TabularDisplay. columns Gets or sets the column names for an instance. This method is called automatically by the constructor with any parameters that are passed to the constructor (if any are passed). When called in scalar context, columns() returns the number of columns in the instance, rather than the columns themselves. In list context, copies of the columns names are returned; the names of the columns cannot be modified this way. add Takes a list of items and appends it to the list of items to be displayed. add() can also take a reference to an array, so that large arrays don't need to be copied. As elements are processed, add() maintains the width of each column so that the resulting table has the correct dimensions. add() returns $self, so that calls to add() can be chained: $t->add(@one)->add(@two)->add(@three); render render() does most of the actual work. It returns a string containing the data added via add(), formatted as a table, with a header containing the column names. render() does not change the state of the object; it can be called multiple times, with identical output (including identical running time: the output of render is not cached). If there are no columns defined, then the output table does not contains a row of column names. Compare these two sequences: my $t = Text::TabularDisplay->new; $t->add(qw< 1 2 3 4 >); $t->add(qw< 5 6 7 8 >); print $t->render; $t->columns(qw< one two three four >); print $t->render; # Example 1 output +---+---+---+---+ | 1 | 2 | 3 | 4 | | 5 | 6 | 7 | 8 | +---+---+---+---+ # Example 2 output +-----+-----+-------+------+ | one | two | three | four | +-----+-----+-------+------+ | 1 | 2 | 3 | 4 | | 5 | 6 | 7 | 8 | +-----+-----+-------+------+ render() takes optional $start and $end arguments; these indicate the start and end indexes for the data to be rendered. This can be used for paging and the like: $t->add(1, 2, 3)->add(4, 5, 6)->add(7, 8, 9)->add(10, 11, 12); print $t->render(0, 1), " "; print $t->render(2, 3), " "; Produces: +-------+--------+-------+ | First | Second | Third | +-------+--------+-------+ | 1 | 2 | 3 | | 4 | 5 | 6 | +-------+--------+-------+ +-------+--------+-------+ | First | Second | Third | +-------+--------+-------+ | 7 | 8 | 9 | | 10 | 11 | 12 | +-------+--------+-------+ As an aside, note the chaining of calls to add(). The elements in the table are padded such that there is the same number of items in each row, including the header. Thus: $t->columns(qw< One Two >); print $t->render; +-----+-----+----+ | One | Two | | +-----+-----+----+ | 1 | 2 | 3 | | 4 | 5 | 6 | | 7 | 8 | 9 | | 10 | 11 | 12 | +-----+-----+----+ And: $t->columns(qw< One Two Three Four>); print $t->render; +-----+-----+-------+------+ | One | Two | Three | Four | +-----+-----+-------+------+ | 1 | 2 | 3 | | | 4 | 5 | 6 | | | 7 | 8 | 9 | | | 10 | 11 | 12 | | +-----+-----+-------+------+ OTHER METHODS
clone() The clone() method returns an identical copy of a Text::TabularDisplay instance, completely separate from the cloned instance. items() The items() method returns the number of elements currently stored in the data structure: printf "There are %d elements in $t. ", $t->items; reset() Reset deletes the data from the instance, including columns. If passed arguments, it passes them to columns(), just like new(). populate() populate() as a special case of add(); populate() expects a reference to an array of references to arrays, such as returned by DBI's selectall_arrayref method: $sql = "SELECT " . join(", ", @c) . " FROM mytable"; $t->columns(@c); $t->populate($dbh->selectall_arrayref($sql)); This is for convenience only; the implementation maps this to multiple calls to add(). NOTES
/ ISSUES Text::TabularDisplay assumes it is handling strings, and does stringy things with the data, like length() and sprintf(). Non-character data can be passed in, of course, but will be treated as strings; this may have ramifications for objects that implement overloading. The biggest issue, though, is that this module duplicates a some of the functionality of Data::ShowTable. Of course, Data::ShowTable is a large, complex monolithic tool that does a lot of things, while Text::TabularDisplay is small and fast. AUTHOR
darren chamberlain <darren@cpan.org> CREDITS
The following people have contributed patches, suggestions, tests, feedback, or good karma: David N. Blank-Edelman Eric Cholet Ken Youens-Clark Michael Fowler Paul Cameron Prakash Kailasa Slaven Rezic Harlan Lieberman-Berg Patrick Kuijvenhoven VERSION
This documentation describes "Text::TabularDisplay" version 1.33. perl v5.14.2 2012-07-05 TabularDisplay(3pm)
All times are GMT -4. The time now is 05:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy