![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Conditional FTP | Dastard | Shell Programming and Scripting | 2 | 06-21-2008 04:38 AM |
| conditional email | ricky007 | Shell Programming and Scripting | 3 | 03-05-2008 10:38 PM |
| AWK - conditional cause | Rafael.Buria | Shell Programming and Scripting | 2 | 01-28-2008 10:24 AM |
| Split a file with no pattern -- Split, Csplit, Awk | madhunk | UNIX for Dummies Questions & Answers | 10 | 12-17-2007 09:57 AM |
| Conditional Statements | cstovall | Shell Programming and Scripting | 1 | 05-15-2005 02:58 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
conditional split
Hi,
Can someone let me know how I can split a record when it contains a vairable length of fields. Code:
Line1 field1,field101,field102,field 103,field104 Line 2 field1,field101,field102,field 103,field104,field201,field202,field 203,field204 Line 3 field1,field101,field102,field 103,field104,field201,field202,field 203,field204,field301,field 302,field303,field304 In the above scenario,I wanna blow up individual record for the number of times the field101..field104 or field201...field204 or field 301..304 exists. So for the above example the expected output would be, Line 1 would remain as such. Line 2 would be splitted into 2 where field101,..field104(record1) and field201..field204(record 2) Line 3 would be splitted into 3 where field101,..field104(record1) ,field201..field204(record 2) and field301..field304(record 3) Appreciate your inputs. Thx |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
For each record, would there be only 4 fields ? Or does that vary. If it varies, then you need to show us what the fields look like.
|
|
#3
|
|||
|
|||
|
Hi,
There would only four fields for each record split. |
|
#4
|
|||
|
|||
|
Code:
ruby -ne 'scan(/([a-z]+ ?(\d)\d*,(?:[a-z]+ ?\2\d*,?)*)/i ).each{|x|
puts x.first.chomp(",") }' myfile
|
|
#5
|
|||
|
|||
|
Hi Futurelet,
could you tell me what is this command 'RUBY' ? Is this pearl ????? Iam looking to acheive this in shell scripting. |
|
#6
|
|||
|
|||
|
Hi Braindrain,
this will work Quote:
Gaurav |
|||
| Google The UNIX and Linux Forums |