Sponsored Content
Full Discussion: Changing table layout
Top Forums UNIX for Dummies Questions & Answers Changing table layout Post 302621117 by beca123456 on Tuesday 10th of April 2012 01:34:03 AM
Old 04-10-2012
Changing table layout

Hi everyone,

I'm a beginner in Unix, and would need some help from you guys!

My input (pipe delimited):
Code:
City|ZIP|Ref. Item
NYC|212|00004
NYC|212|00032
NYC|212|00006
LA|90049|00068
LA|90049|00009
SF|94131|0027

You can see that the first 3 lines have column 1 and 2 in common, same for lines 4 and 5.
I need to rearrange this table by putting together all the items (column 3) belonging to the same city.

Using awk, I would like to obtain something like that:
Code:
City: NYC
ZIP: 212
Ref. Item: 00004
Ref. Item: 00032
Ref. Item: 00006

City: LA
ZIP: 90049
Ref. Item: 00068
Ref. Item: 00009

City: SF
ZIP: 94131
Ref. Item: 0027

I managed to output the table like that:
Code:
City: NYC
ZIP: 212
Ref. Item: 00004

City: NYC
ZIP: 212
Ref. Item: 00032

City: NYC
ZIP: 212
Ref. Item: 00006

City: LA
ZIP: 90049
Ref. Item: 00068

City: LA
ZIP: 90049
Ref. Item: 00009

City: SF
ZIP: 94131
Ref. Item: 0027


But I cannot remove the duplicate in $1 and $2 to obtain what I want...Smilie

Any advice would be welcome !

---------- Post updated 10-04-12 at 12:34 AM ---------- Previous update was 09-04-12 at 09:41 PM ----------

I changed my strategy, and now I obtain this output:

Code:
City: NYC
ZIP: 212
Ref. Item: 00004
Ref. Item: 00032
Ref. Item: 00006
City: LA
ZIP: 90049
Ref. Item: 00068
Ref. Item: 00009
City: SF
ZIP: 94131
Ref. Item: 0027

So my question now is how can I insert a blank line between the last line beginning by "Ref." and the line beginning by "City" ?

As I have a variable number of lines with "Ref.", I cannot use stuff like
Code:
NR % <number> == 0


Last edited by beca123456; 04-10-2012 at 01:37 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Changing Keyboard layout

Hi, How do i go about changing the keyboard layout to the UK layout. currently the @ symbol on the keyboard appears as a " sybol on the monitor. Many Thanks in advance Kam (1 Reply)
Discussion started by: vishnura
1 Replies

2. Linux

Changing default keyboard layout in Linux

Hi I have Fedora linux with XFCE desktop. I want to use Indic lanquage in that. I have installed unicode devnagri fonts. But I am not able to change my default keyboard layout. How can I change default keyboard layout in XFCE or through command line. Thanks NeeleshG (0 Replies)
Discussion started by: neel.gurjar
0 Replies

3. Shell Programming and Scripting

select values from db1 table and insert into table of DB2

Hi I am having three oracle databases running in three different machine. their ip address is different. from one of the DB am able to access both the databases.(means am able to select values and insert values in to tables individually.) I need to fetch some data from DB1 table(say DB1 ip is... (2 Replies)
Discussion started by: aemunathan
2 Replies

4. UNIX and Linux Applications

create table via stored procedure (passing the table name to it)

hi there, I am trying to create a stored procedure that i can pass the table name to and it will create a table with that name. but for some reason it creates with what i have defined as the variable name . In the case of the example below it creates a table called 'tname' for example ... (6 Replies)
Discussion started by: rethink
6 Replies

5. UNIX for Dummies Questions & Answers

Creating a condensed table from a pre-existing table in putty

Hello, I'm working with putty on Windows 7 professional and I'd like to know if there's a way to gather specific lines from a pre-existing table and make a new table with that information. More specifically, I'd like the program to look at a specific column, say column N, and see if any of the... (5 Replies)
Discussion started by: Deedee393
5 Replies

6. Shell Programming and Scripting

Help with changing text file layout

Hi there, I am with this one column input text file to change layout, please help. Thanks. I have awk, sed. $ cat input Median 1.0 2.3 3.0 Median 35.0 26.3 45.7 10.1 63.1 Median 1.2 2.3 (8 Replies)
Discussion started by: cwzkevin
8 Replies

7. Shell Programming and Scripting

Build a table from a list by comparing existing table entries

I am new to this shell scripting.... I have a file which contains list of users. This files get updated when new user comes into the system. I want to create script which will give a table containing unique list of users. When I say unique, it means script should match table while parsing... (3 Replies)
Discussion started by: dchavan1901
3 Replies

8. UNIX and Linux Applications

Help in copying table structure to another table with constraints in Oracle

hi, i need to copy one table with data into another table, right now am using create table table1 as select * from table2 i want the constraints of table1 to be copied to table2 also , can anyone give me some solution to copy the constraints also, now am using oracle 10.2.0.3.0... (1 Reply)
Discussion started by: senkerth
1 Replies

9. UNIX for Dummies Questions & Answers

Vi. changing txt into table

just discover this thread. It sounds perfect for me because I am following an online course on command line tools and some instruction ... seems not be replicable on my Terminal Here is an example on a txt file with n rows each containing 3 word separated by a space. a b c d e f .... ... (5 Replies)
Discussion started by: mrMe
5 Replies

10. Web Development

Getting Rid of Annoying Bootstrap Table Borders and Wayward Table Lines

Bootstrap is great; but we have had some issues with Bootstrapped <tables> (and legacy <fieldset> elements) showing annoying, wayward lines. I solved that problem today with this simple jQuery in the footer: <script> $(function(){ $('tr, td, fieldset,... (0 Replies)
Discussion started by: Neo
0 Replies
Menu::Item(3)						User Contributed Perl Documentation					     Menu::Item(3)

NAME
Tk::Menu::Item - Base class for Menu items SYNOPSIS
require Tk::Menu::Item; my $but = $menu->Button(...); $but->configure(...); my $what = $but->cget(); package Whatever; require Tk::Menu::Item; @ISA = qw(Tk::Menu::Item); sub PreInit { my ($class,$menu,$info) = @_; $info->{'-xxxxx'} = ... my $y = delete $info->{'-yyyy'}; } DESCRIPTION
Tk::Menu::Item is the base class from which Tk::Menu::Button, Tk::Menu::Cascade, Tk::Menu::Radiobutton and Tk::Menu::Checkbutton are derived. There is also a Tk::Menu::Separator. Constructors are declared so that $menu->Button(...) etc. do what you would expect. The "-label" option is pre-processed allowing ~ to be prefixed to the character to derive a "-underline" value. Thus $menu->Button(-label => 'Goto ~Home',...) is equivalent to $menu->Button(-label => 'Goto Home', -underline => 6, ...) The "Cascade" menu item creates a sub-menu and accepts these options: -menuitems A list of items for the sub-menu. Within this list (which is also accepted by Menu and Menubutton) the first two elements of each item should be the "constructor" name and the label: -menuitems => [ [Button => '~Quit', -command => [destroy => $mw]], [Checkbutton => '~Oil', -variable => $oil], ] -postcommand A callback to be invoked before posting the menu. -tearoff Specifies whether sub-menu can be torn-off or not. -menuvar Scalar reference that will be set to the newly-created sub-menu. The returned object is currently a blessed reference to an array of two items: the containing Menu and the 'label'. Methods "configure" and "cget" are mapped onto underlying "entryconfigure" and "entrycget". The main purpose of the OO interface is to allow derived item classes to be defined which pre-set the options used to create a more basic item. BUGS
This OO interface is very new. Using the label as the "key" is a problem for separaror items which don't have one. The alternative would be to use an index into the menu but that is a problem if items are deleted (or inserted other than at the end). There should probably be a PostInit entry point too, or a more widget like defered 'configure'. perl v5.12.1 2007-05-05 Menu::Item(3)
All times are GMT -4. The time now is 07:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy