The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Conditional FTP Dastard Shell Programming and Scripting 2 06-21-2008 07:38 AM
conditional email ricky007 Shell Programming and Scripting 3 03-06-2008 01:38 AM
AWK - conditional cause Rafael.Buria Shell Programming and Scripting 2 01-28-2008 01:24 PM
Split a file with no pattern -- Split, Csplit, Awk madhunk UNIX for Dummies Questions & Answers 10 12-17-2007 12:57 PM
Conditional Statements cstovall Shell Programming and Scripting 1 05-15-2005 05:58 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-07-2006
braindrain braindrain is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 67
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
  #2 (permalink)  
Old 03-08-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
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 (permalink)  
Old 03-10-2006
braindrain braindrain is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 67
Hi,
There would only four fields for each record split.
  #4 (permalink)  
Old 03-10-2006
futurelet futurelet is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 137
Code:
ruby -ne 'scan(/([a-z]+ ?(\d)\d*,(?:[a-z]+ ?\2\d*,?)*)/i ).each{|x|
  puts x.first.chomp(",") }' myfile
  #5 (permalink)  
Old 03-10-2006
braindrain braindrain is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 67
Hi Futurelet,
could you tell me what is this command 'RUBY' ? Is this pearl ?????
Iam looking to acheive this in shell scripting.
  #6 (permalink)  
Old 03-11-2006
gauravgoel gauravgoel is offline
Registered User
  
 

Join Date: Dec 2005
Location: India
Posts: 218
Hi Braindrain,

this will work

Quote:
$ cat f1.txt|awk -F ',' '{
> for(i=1;i<NF;i+=4)
> print $i, $(i+1), $(i+2), $(i+3)
> }'
where f1.txt is ur input file,

Gaurav
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 02:41 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