Sponsored Content
Top Forums Shell Programming and Scripting Breaking a column's value into multiple rows Post 302469992 by mehimadri on Monday 8th of November 2010 11:18:45 PM
Old 11-09-2010
Breaking a column's value into multiple rows

Hello Friends,

I am trying to implement the following using UNIX. I am getting a sequential file as input which would have two columns, "Name" and "Countries Visited". The "Countries Visisted" field will be multi-valued, each value separated by a space and also the number of values are not fixed. The file is tab delimited.
For example,
Name Countries Visited
A US UK CA
B US HT UG CA IN
C US
D CN PA
My intended output is this:
Name Countries Visited
A US
A UK
A CA
B US
B HT
B UG
B CA
B IN
C US
D CN
D PA
How can I use UNIX Shell Scripting to do this?
Many Thanks!!

regards
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting Single Column into Multiple rows

i have single column which is starting with same string(many number of rows) i have to convert each into a single row.how can i do that? laknar std mes 23 55 laknar isd phone no address amount 99 I have to convert above like below. laknar|std|mes|23|55 laknar|isd|phone... (3 Replies)
Discussion started by: laknar
3 Replies

2. Shell Programming and Scripting

Single column into multiple rows

Hi all, I need to convert this file having just one column into two column file current file: a 15 b 21 c 34 d 48 e 10 wanted: a 15 b 21 c 34 (15 Replies)
Discussion started by: prachiagra
15 Replies

3. Shell Programming and Scripting

How to merge multiple rows into single row if first column matches ?

Hi, Can anyone suggest quick way to get desired output? Sample input file content: A 12 9 A -0.3 2.3 B 1.0 -4 C 34 1000 C -111 900 C 99 0.09 Output required: A 12 9 -0.3 2.3 B 1.0 -4 C 34 1000 -111 900 99 0.09 Thanks (3 Replies)
Discussion started by: cbm_000
3 Replies

4. UNIX for Dummies Questions & Answers

[SOLVED] splitting a single column(with spaces) into multiple rows

Hi All, My requisite is to split a single column of phonemes seperated by spaces into multiple rows. my input file is: a dh u th a qn ch A v U r k my o/p should be like: adhu a dh u (3 Replies)
Discussion started by: girlofgenuine
3 Replies

5. Shell Programming and Scripting

Converting Single Column into Multiple rows, but with strings to specific tab column

Dear fellows, I need your help. I'm trying to write a script to convert a single column into multiple rows. But it need to recognize the beginning of the string and set it to its specific Column number. Each Line (loop) begins with digit (RANGE). At this moment it's kind of working, but it... (6 Replies)
Discussion started by: AK47
6 Replies

6. Shell Programming and Scripting

Convert single column into multiple rows

Convert Single column to multiple rows file a.txt contains data like below Server=abc Run=1 Tables=10 Sessions=16 Time=380 Jobs=5 Server=abc Run=2 Tables=15 Sessions=16 Time=400 Jobs=5 Server=abc Run=3 Tables=20 Sessions=16 Time=450 (5 Replies)
Discussion started by: sol_nov
5 Replies

7. Shell Programming and Scripting

Converting Single Column into Multiple rows

Hi .. anyone can you help me ? i need to convert text below into multiple columns interface; GigabitEthernet0/0/0/0 description; TRUNK_PE-D2-JT2-VPN_Gi0/0/0/0_TO_ME4-A-JKT-JT_4/1/1_1G mtu 9212 negotiation auto interface; GigabitEthernet0/0/0/0.11 description; tes encapsulation;... (1 Reply)
Discussion started by: mad3linux
1 Replies

8. UNIX for Beginners Questions & Answers

How to transpose pieces of data in a column to multiple rows?

Hello Everyone, I am very new to the world of regular expressions. I am trying to use grep/sed for the following: Input file is something like this and there are multiple such files: abc 1 2 3 4 5 ***END*** abc 6 7 8 9 ***END*** abc 10 (2 Replies)
Discussion started by: shellnewuser
2 Replies

9. UNIX for Beginners Questions & Answers

Compare values in multiple rows in one column using awk

I would like to compare values in column 8, and grep the ones where the different is > 1, columns 1 and 2 are the key for array. Every 4 rows the records values in columns 1 and 2 changed. Then, the comparison in the column 8 need to be done for the 4 rows everytime columns 1 and 2 changed ... (4 Replies)
Discussion started by: jiam912
4 Replies

10. UNIX for Beginners Questions & Answers

How to split one long column into multiple rows with 3 each ?

I have a large csv dataset like this : A value1 A value2 A value3 B value1 B value2 B value3 C value1 C value2 C value3 what I expected output is :A value1 value2 value3 B value1 value2 value3 C value1 value2 value3 I'm thinking of use like awk, columns , but haven't find a proper... (4 Replies)
Discussion started by: nengcheng
4 Replies
Geography::Countries(3pm)				User Contributed Perl Documentation				 Geography::Countries(3pm)

NAME
Geography::Countries - 2-letter, 3-letter, and numerical codes for countries. SYNOPSIS
use Geography::Countries; $country = country 'DE'; # 'Germany' @list = country 666; # ('PM', 'SPM', 666, # 'Saint Pierre and Miquelon', 1) DESCRIPTION
This module maps country names, and their 2-letter, 3-letter and numerical codes, as defined by the ISO-3166 maintenance agency [1], and defined by the UNSD. The "country" subroutine. This subroutine is exported by default. It takes a 2-letter, 3-letter or numerical code, or a country name as argument. In scalar context, it will return the country name, in list context, it will return a list consisting of the 2-letter code, the 3-letter code, the numerical code, the country name, and a flag, which is explained below. Note that not all countries have all 3 codes; if a code is unknown, the undefined value is returned. There are 3 categories of countries. The largest category are the current countries. Then there is a small set of countries that no longer exist. The final set consists of areas consisting of multiple countries, like Africa. No 2-letter or 3-letter codes are available for the second two sets. (ISO 3166-3 [3] defines 4 letter codes for the set of countries that no longer exist, but the author of this module was unable to get her hands on that standard.) By default, "country" only returns countries from the first set, but this can be changed by giving "country" an optional second argument. The module optionally exports the constants "CNT_F_REGULAR", "CNT_F_OLD", "CNT_F_REGION" and "CNT_F_ANY". These constants can also be important all at once by using the tag ":FLAGS". "CNT_F_ANY" is just the binary or of the three other flags. The second argument of "country" should be the binary or of a subset of the flags "CNT_F_REGULAR", "CNT_F_OLD", and "CNT_F_REGION" - if no, or a false, second argument is given, "CNT_F_REGULAR" is assumed. If "CNT_F_REGULAR" is set, regular (current) countries will be returned; if "CNT_F_OLD" is set, old, no longer existing, countries will be returned, while "CNT_F_REGION" is used in case a region (not necessarely) a country might be returned. If "country" is used in list context, the fifth returned element is one of "CNT_F_REGULAR", "CNT_F_OLD" and "CNT_F_REGION", indicating whether the result is a regular country, an old country, or a region. In list context, "country" returns a 5 element list. To avoid having to remember which element is in which index, the constants "CNT_I_CODE2", "CNT_I_CODE3", "CNT_I_NUMCODE", "CNT_I_COUNTRY" and "CNT_I_FLAG" can be imported. Those constants contain the indices of the 2-letter code, the 3-letter code, the numerical code, the country, and the flag explained above, respectively. All index constants can be imported by using the ":INDICES" tag. The "code2", "code3", "numcode" and "countries" routines. All known 2-letter codes, 3-letter codes, numerical codes and country names can be returned by the routines "code2", "code3", "numcode" and "countries". None of these methods is exported by default; all need to be imported if one wants to use them. The tag ":LISTS" imports them all. In scalar context, the number of known codes or countries is returned. REFERENCES
The 2-letter codes come from the ISO 3166-1:1997 standard [2]. ISO 3166 bases its list of country names on the list of names published by the United Nations. This list is published by the Statistical Division of the United Nations [4]. The UNSD uses 3-letter codes, and numerical codes [5]. The information about old countries [6] and regions [7] also comes from the United Nations. In a few cases, there was a conflict between the way how the United Nations spelled a name, and how ISO 3166 spells it. In most cases, is was word order (for instance whether The republic of should preceed the name, or come after the name. A few cases had minor spelling variations. In all such cases, the method in which the UN spelled the name was choosen; ISO 3166 claims to take the names from the UN, so we consider the UN authoritative. [1] ISO Maintenance Agency (ISO 3166/MA) http://www.din.de/gremien/nas/nabd/iso3166ma/index.html. [2] Country codes, http://www.din.de/gremien/nas/nabd/iso3166ma/codlstp1.html, 7 September 1999. [3] ISO 3166-3, Code for formerly used country names. http://www.din.de/gremien/nas/nabd/iso3166ma/info_pt3.html. [4] United Nations, Statistics Division. http://www.un.org/Depts/unsd/statdiv.htm. [5] Country or area codes in alphabetical order. http://www.un.org/Depts/unsd/methods/m49alpha.htm, 26 August 1999. [6] Codes added or changed. http://www.un.org/Depts/unsd/methods/m49chang.htm, 26 August 1999. [7] Geographical regions. http://www.un.org/Depts/unsd/methods/m49regin.htm, 26 August 1999. BUGS
Looking up information using country names is far from perfect. Except for case and the amount of white space, the exact name as it appears on the list has to be given. USA will not return anything, but United States will. DEVELOPMENT
The current sources of this module are found on github, <git://github.com/Abigail/geography--countries.git>. AUTHOR
Abigail <mailto:geography-countries@abigail.be>. COPYRIGHT and LICENSE Copyright (C) 1999, 2009 by Abigail Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. perl v5.10.1 2010-12-17 Geography::Countries(3pm)
All times are GMT -4. The time now is 12:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy