The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Break a file into separate files chiru_h Shell Programming and Scripting 8 07-29-2008 04:06 AM
To read and separate number and words in file and store to two new file using shell kamakshi s Shell Programming and Scripting 2 06-26-2008 08:39 AM
Separate based on file names prashk15 Shell Programming and Scripting 2 02-04-2008 09:37 AM
Output of command to 2 separate file? TheCrunge UNIX for Dummies Questions & Answers 2 12-08-2005 04:45 PM
Separate a portion of text file into another file srikanth_ksv Shell Programming and Scripting 4 08-05-2005 09:11 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-13-2008
vinsara vinsara is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 15
How to separate file content

Hi All,

I have a file like below which is having 3 fields namely companycode, companylocation & companyaddress and i want to separate all the fields individually.

How can i do?

File Structure:
----------------

Code:
Aberdeen Centre [Blks A-U  & CP]    Aberdeen        The Ming An Ins Co (HK) Ltd 
Academic Terrace [Towers 1-3]    "101 Pokfulam Road, HK"        Zurich Insurance Co Ltd 
Academic Terrace [Car Park Portion]    "102 Pokfulam Road, HK"        Concord Insurance Co Ltd 
Admiralty Centre [Towers I & II]    MTRC Property        Zurich Insurance Co Ltd 
"Aegean Coast [Blks 1-3, 5-8 & CP]"    So Kwun Wat        Sun Hung Kai Properites Ins Ltd 
Affluence Garden [Blks 1-5 & CP & Nursery]    Tuen Mun        China Pacific Insurance Co (HK) Ltd 
Aldrich Garden [Blks 1-10 & CP]    "2 Oi Lai Street, Shau Kei Wan"        Concord Insurance Co Ltd 
All Fit Garden [Blk A - D & CP]    20-22 Bonham Road        Asia Insurance Co Ltd 
"Allway Gardens [A-H,J-N,P-R & CP]"    "No.191 Tsuen King Circuit, Tsuen Wan, NT"        Asia Insurance Co Ltd 
Amoy Gardens [Blks A-S]    "77 Ngau Tau Kau Road, Kowloon Bay"        The Ming An Ins Co (HK) Ltd 
Anglers' Bay [Towers I & II & CP]    "No.18A Castle Peak Road, Sham Tseng, Tsuen Wan, NT"        Bank of China Group Ins Co Ltd 
"Aqua Marine [Blk 1-3, 5-6 & CP]"    "8 Sham Shing Road, Cheung Sha Wan"        The Ming An Ins Co (HK) Ltd 
Avalon [Blk A - B]    Tai Hang        Wing Hang Zurich Insurance Co Ltd 
Baguio Villa [Blk 41-44]    550 - 555 Victoria Road        Asia Insurance Co Ltd 
Balwin Court [Blk 1-5 & CP]    Mongkok        Asia Insurance Co Ltd 
Banyan Garden Phase I [Blks 1-3  & CP]    "863 Lai Chi Kok Road, Cheung Sha Wan"        The Ming An Ins Co (HK) Ltd 
Banyan Garden Phase II [Blks 7-8 & CP]    "863 Lai Chi Kok Road, Cheung Sha Wan"        The Ming An Ins Co (HK) Ltd 
Banyan Garden Phase III [Blks 5-6 & CP]    "863 Lai Chi Kok Road, Cheung Sha Wan"        The Ming An Ins Co (HK) Ltd 
Bauhinia Garden [Blks & CP]    Hung Shui Kiu        The Ming An Ins Co (HK) Ltd 
"Bauhinia Garden - TKO [Blks 1-8 ,CP & Commercial blk]"    "11 Tong Chun Street, Tseung Kwan O"        HSBC Insurance Limited 
Bay View Garden [Blks 1-3 & CP]    "Wing Ting Road, Ngau Chi Wan"        Zurich Insurance Co Ltd 
Bay View Mansion [Blks A-B & CP]    Moreton Terrace        HSBC Insurance Limited 
Baycrest [Blks 1-6 & CP]    "8 Hang Ming Street, Ma On Shan"        Sun Hung Kai Properites Ins Ltd 
Bayshore Apartments [Blk A - D]    Aberdeen        Royal & Sun Alliance Ins Co Ltd 
Bayshore Towers [Blks 1-6 & CP]    "608 Sai Sha Road, Ma On Shan"        The Ming An Insurance Co (HK) Ltd 
Bayview Garden [Blks 1-5 & CP]    Tsuen Wan        Asia Insurance Co Ltd 
Bayview Mansion [Blk A - B & CP]    "No.21 Moreton Terrace, Causeway Bay"        HSBC Insurance (Asia) Ltd. 
Bayview Terrace [Blk 1 - 26 & CP]    "107 Castle Peak Road, Tuen Mun"        "China BOCOM Insurance Co., Ltd." 
Beacon Heights [Blks 1-19 & CP]    Kowloon Tong        AXA General Insurance Hong Kong Ltd 
Beauty Court [Blks & CP]    Mid-Level        The Ming An Ins Co (HK) Ltd 
Bel Air Heights [Blks 1-4]    "Lung Poon Street / Fung Tak Road, Diamond Hill"        Asia Insurance Co Ltd 
Belair Monte [Blks 1-7 & CP]    "3 Ma Sik Road, Fanling"        Concord Insurance Co Ltd 
Belvedere Garden (Phase 1) [PH01 Blks 1-3 & CP]    Tsuen Wan        The Ming An Ins Co (HK) Ltd 
Belvedere Garden (Phase 2) [PH02 Blks 1-9 & CP]    Tsuen Wan        The People's Insurance Co of China  
Belvedere Garden (Phase 3) [PH03 Blks 1-7 & CP]    Tsuen Wan        The Ming An Ins Co (HK) Ltd 
"Beneville [Blks 1-3, 5 & CP]"    "18 Tuen Kwai Road, Tuen Mun"        Sun Hung Kai Properites Ins Ltd 
Beverly Garden  [Blks 1-10 & CP]    Tseung Kwan O        Allianz Insurance (HK) Ltd

Thanks in advance.

Last edited by jim mcnamara; 08-13-2008 at 04:11 PM..
  #2 (permalink)  
Old 08-13-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,814
There is no "pattern" as what divides the fields into 3 indentifiable fields. Is it by column?
ie field 1 goes from Col 1 - 34, Col 2 35 - 102, etc. Or the gaps of several white spaces?
  #3 (permalink)  
Old 08-13-2008
vinsara vinsara is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 15
Hi..

The first column ends after this symbol ].
then the remaining words of each line is 2nd and 3rd columns respectively.

Eg.
Aberdeen Centre [Blks A-U & CP] is the first column value.
--------------------------------
Aberdeen is the second column value.
--------
The Ming An Ins Co (HK) Ltd is the third column value.
---------------------------


Based on this value i want to split the content individually. Please help me.

Thanks.
  #4 (permalink)  
Old 08-14-2008
vinsara vinsara is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 15
Hi All,

Please somebody help me on this..
I believe, I have given the sufficient details.
If anybody wants more details please let me know.

Thanks in advance.
  #5 (permalink)  
Old 08-14-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,423
please post input content and expected output content
  #6 (permalink)  
Old 08-14-2008
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321

Code:
awk -F'   +' '{printf"%-60s%-60s%s\n", $1,$2,$3}' file

or if you have more than 3 fields



Code:
awk -F'   +' '{for(i=1;i<=NF;i++) printf"%-60s",$i; print ""}' file

  #7 (permalink)  
Old 08-14-2008
runmeat6 runmeat6 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 11
Maybe
sed s/\ \ \ \ /:/g filename | awk -F: '{print $1}'
sed s/\ \ \ \ /:/g filename | awk -F: '{print $2}'
sed s/\ \ \ \ /:/g filename | awk -F: '{print $4}'
might work assuming the spacing is correctly presented in the example code (i.e. four spaces between columns 1 and 2 and eight spaces between columns 2 and 3) and there are never as many as four spaces anywhere but in the separation of fields. The colon ":" may be substituted for any character that does not appear in the file.

(As an aside
sed s/\ \ \ \ /:/g filename | awk -F: '{print $3}'
was intentionally skipped as this would produce nothing given the above assumptions are correct.)
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:06 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0