![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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.. |
|
||||
|
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. |
|
||||
|
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.) |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|