Sponsored Content
Top Forums Shell Programming and Scripting How to write to different files based on a column Post 302638507 by ramky79 on Thursday 10th of May 2012 10:54:55 AM
Old 05-10-2012
How to write to different files based on a column

Hi,
I have the following sample file

Code:
32895901-d17f-414c-ac93-3e7e0f5ec240	AND	@GDF_INPUT[BaseName:CATALUNYA; HouseNumber:1; ISOCountryCode:AND; PostalCode:AD200; LanguageCode:GER; ]
73b129e1-1fa9-4c0d-b95b-4682e5389612	AUS	@GDF_INPUT[BaseName:MARKET STREET; HouseNumber:68; Builtup:SYDNEY; ISOCountryCode:AUS; PostalCode:NSW 2000; LanguageCode:GER; ]
40f82e88-d1ff-4ce2-9b8e-d827ddb39447	BEL	@GDF_INPUT[BaseName:CHAUSSEE DE CHARLEROI; HouseNumber:38; Order8:BRUSSELS; ISOCountryCode:BEL; PostalCode:1060; LanguageCode:GER; ]
ffbcc6fe-ba35-489c-ae08-e70e8897aa23	BEL	@FF_INPUT[AddressString: TUNNEL BRABANT PASSAGE CHARLES ROGIER 23D, BRUSSELS, , 1210; ISOCountryCode: BEL; LanguageCode: ENG]
b6c0a729-c8ae-4737-8e73-b28d017e145c	BEL	@FF_INPUT[AddressString: TUNNEL BRABANT PASSAGE CHARLES ROGIER 23D, BRUSSELS, , 1210; ISOCountryCode: BEL; LanguageCode: ENG]
9ab36071-ba17-4dd7-b6bd-50b268044f23	BEL	@FF_INPUT[AddressString: TUNNEL BRABANT PASSAGE CHARLES ROGIER 23D, BRUSSELS, , 1210; ISOCountryCode: BEL; LanguageCode: ENG]
36e9c3f1-042a-43a4-a80e-4a3bc2513d01	BGR	@GDF_INPUT[BaseName:BULGARIA BOULEVARD; HouseNumber:1; Builtup:SOFIA; ISOCountryCode:BGR; PostalCode:1421; LanguageCode:GER; ]
5436ab97-876e-4f34-b9ff-e52858b06cf1	BMU	@FF_INPUT[AddressString: 60 TUCKER'S POINT DRIVE HAMILTON PARISH, HS 02 BMU; ISOCountryCode: BMU; LanguageCode: ENG]

I would like to separate the data in this file into several files based on column3

Ex:
I want all the lines that start with @GDF_INPUT in column3 to be in one file and all the lines that start with @FF_INPUT in column3 in another file

File1:
Code:
32895901-d17f-414c-ac93-3e7e0f5ec240	AND	@GDF_INPUT[BaseName:CATALUNYA; HouseNumber:1; ISOCountryCode:AND; PostalCode:AD200; LanguageCode:GER; ]
73b129e1-1fa9-4c0d-b95b-4682e5389612	AUS	@GDF_INPUT[BaseName:MARKET STREET; HouseNumber:68; Builtup:SYDNEY; ISOCountryCode:AUS; PostalCode:NSW 2000; LanguageCode:GER; ]
40f82e88-d1ff-4ce2-9b8e-d827ddb39447	BEL	@GDF_INPUT[BaseName:CHAUSSEE DE CHARLEROI; HouseNumber:38; Order8:BRUSSELS; ISOCountryCode:BEL; PostalCode:1060; LanguageCode:GER; ]
36e9c3f1-042a-43a4-a80e-4a3bc2513d01	BGR	@GDF_INPUT[BaseName:BULGARIA BOULEVARD; HouseNumber:1; Builtup:SOFIA; ISOCountryCode:BGR; PostalCode:1421; LanguageCode:GER; ]

File2:
Code:
ffbcc6fe-ba35-489c-ae08-e70e8897aa23	BEL	@FF_INPUT[AddressString: TUNNEL BRABANT PASSAGE CHARLES ROGIER 23D, BRUSSELS, , 1210; ISOCountryCode: BEL; LanguageCode: ENG]
b6c0a729-c8ae-4737-8e73-b28d017e145c	BEL	@FF_INPUT[AddressString: TUNNEL BRABANT PASSAGE CHARLES ROGIER 23D, BRUSSELS, , 1210; ISOCountryCode: BEL; LanguageCode: ENG]
9ab36071-ba17-4dd7-b6bd-50b268044f23	BEL	@FF_INPUT[AddressString: TUNNEL BRABANT PASSAGE CHARLES ROGIER 23D, BRUSSELS, , 1210; ISOCountryCode: BEL; LanguageCode: ENG]
5436ab97-876e-4f34-b9ff-e52858b06cf1	BMU	@FF_INPUT[AddressString: 60 TUCKER'S POINT DRIVE HAMILTON PARISH, HS 02 BMU; ISOCountryCode: BMU; LanguageCode: ENG]

How do i do this...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Merge Two Files based on First column

Hi, I need to join two files based on first column of both files.If first column of first file matches with the first column of second file, then the lines should be merged together and go for next line to check. It is something like: File one: 110001 abc efd 110002 fgh dfg 110003 ... (10 Replies)
Discussion started by: apjneeraj
10 Replies

2. Shell Programming and Scripting

Compare files column to column based on keys

Here is my situation. I need to compare two tab separated files (diff is not useful since there could be known difference between files). I have found similar posts , but not fully matching.I was thinking of writing a shell script using cut and grep and while loop but after going thru posts it... (2 Replies)
Discussion started by: blackjack101
2 Replies

3. Shell Programming and Scripting

Matching 2 files based on one column

Hi, On a similar subject, the following. I have two files: file1.txt dbSNP_rsID,Chromosome,Position,Gene rs10399749,chr. 01,45162,? rs4030303,chr. 01,72434,? rs4030300,chr. 01,72515,? rs940550,chr. 01,78032,? rs13328714,chr. 01,81468,? rs11490937,chr. 01,222077,? rs6683466,chr.... (5 Replies)
Discussion started by: swvanderlaan
5 Replies

4. Shell Programming and Scripting

merging two files based on first column

I had two files file1 and file2. I want a o/p file(file3) like below using first column as ref. Pls give suggestion ass join is not working as the number of lines in each file is nealry 5 C? file1 --------------------- 404000324810001 Y 404000324810004 N 404000324810008 Y 404000324810009 N... (1 Reply)
Discussion started by: p_sai_ias
1 Replies

5. Shell Programming and Scripting

join two files based on one column

Hi All, I am trying to join to files based on one common column. Cat File1 ID HID Ab_1 23 Cd 45 df 22 Vv 33 Cat File2 ID pval Ab_1 0.3 Cd 10 Vv 0.0444 (3 Replies)
Discussion started by: newpro
3 Replies

6. Shell Programming and Scripting

Merge files based on the column value

Hi Friends, I have a file file1.txt 1|ABC|3|jul|dhj 2|NHU|4|kil|eu 3|hjd|34|hfd|43 file2.txt 1||3|KING|dhj 2|NHU||k| 3|hjd|34|hd|43 i want to merge file1.txt file2.txt based on the column null values in file2.txif there are any nulls in column values , (5 Replies)
Discussion started by: i150371485
5 Replies

7. Shell Programming and Scripting

Compare two files based on column

Hi, I have two files roughly 1200 fields in length for each row, sorted on the 2nd field. I need to compare based on that 2nd column between file1 and file2 and print lines that exist in both files into separate files (I can't guarantee that every line in file1 is in file2). Example: File1: ... (1 Reply)
Discussion started by: origon
1 Replies

8. UNIX for Dummies Questions & Answers

Join 2 files based on certain column

I have file input1.txt 11103|11|OTTAWA|City|AA|CAR|0|0|1|-1|0|8526|2014-09-07 23:00:14 11103|11|OTTAWA|City|BB|TRAIN|0|0|2|-2|6|6359|2014-09-07 23:00:14 11104|11|CANADA|City|CC|CAR|0|0|2|-2|0|5947|2014-09-07 23:00:14 11104|11|CANADA|City|DD|TRAIN|0|0|2|-2|1|4523|2014-09-07 23:00:14... (5 Replies)
Discussion started by: radius
5 Replies

9. UNIX for Dummies Questions & Answers

Add 1 column based on name of files

Hi all, I already transferred list of files from ftp server with files name end with $Y$m$d Example my files data_20140101.xls data_20140102.xls data-20140103.xls and content of each files, for example data_20140101.xls USA|16846481|8871374|534909|0|0|0|700|5351981|0|31605445... (6 Replies)
Discussion started by: radius
6 Replies

10. UNIX for Beginners Questions & Answers

Add New Column Based on Files Name

Dear Sir, I need to add new column (last column) based on files name. my files name 20170809_target_tdc_pmx4.xls 20170809_target_tdc_pmx5.xls 20170809_target_tdc_pmx6.xls for example file : 20170809_target_tdc_pmx4.xls Item code Quantity Unit price Serial number... (1 Reply)
Discussion started by: radius
1 Replies
BEL(1)																	    BEL(1)

NAME
bel - open a shell or execute a command on a remote computer through several machines SYNOPSIS
bel [-e file] [-s file] [-d delay] DESCRIPTION
bel generates a script allowing the user to open a shell or execute a command on a remote computer through several machines. In order to generate the script, the user gives the paths to the different machines until the final one is reached. Several paths may be specified in a single entry file or through the standard input. OPTIONS
-e, --entree=FILE Provide the necessary information to establish the tunnel between the source and the final computer. -s, --repertoire-sortie=DIRECTORY The directory where you want to put the generated scripts. -d, --delai=SECONDS Delay to wait before each sent command, in seconds. AUTHOR
Carl Chenet <chaica@ohmytux.com[]> RESSOURCES
Belier homepage : http://www.ohmytux.com/belier LICENSE
Copyright (C) <2009> <Carl Chenet>This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. 05/16/2009 BEL(1)
All times are GMT -4. The time now is 02:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy