The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
need for loop to include fields as one line prkfriryce Shell Programming and Scripting 8 03-23-2007 09:49 AM
fill a NIL into the blank field happyv Shell Programming and Scripting 8 03-23-2007 01:49 AM
field separator as regexp Abhishek Ghose Shell Programming and Scripting 2 02-15-2006 05:49 PM
awk: How to check if field is blank? yongho Shell Programming and Scripting 7 06-09-2005 08:35 AM
How do I specify tab as field separator for sort? SSteve UNIX for Dummies Questions & Answers 8 04-26-2005 01:39 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #15  
Old 07-12-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
Perderabo's solution is a nice hack.

Just one question on that. Wouldnt the column number change if num1a and num1b are different in length ?

Thanks,
Vino
Reply With Quote
Forum Sponsor
  #16  
Old 07-12-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
Quote:
Originally Posted by vino
Perderabo's solution is a nice hack.

Just one question on that. Wouldnt the column number change if num1a and num1b are different in length ?

Thanks,
Vino
Not if num2a and num2b always start in, say, column 20. You put a separator just before column 20. Now there are a variable number of spaces before the separator. If num1a was 10 digits, it would have 9 spaces following it. If num1b was 5 digits, it would have 14 spaces following it. The variable number of spaces allowed both num2a and num2b to start in the same column. My solution depends on that variable number of spaces.
Reply With Quote
  #17  
Old 07-12-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
I think the only constant is the number of fields - the width may vary from line to line.
This is just an assumption - I've been proven wrong before.

Need OPs clarification.

Last edited by vgersh99; 07-12-2005 at 10:18 AM.
Reply With Quote
  #18  
Old 07-12-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
Perderabo,

That is true, indeed.

And like vgersh99 said, the OP has to step in.

Cheers'
Vino
Reply With Quote
  #19  
Old 07-13-2005
ReV ReV is offline
Registered User
 

Join Date: Jun 2005
Posts: 34
Hi,

Thanks all for the helpful solutions. The fields in each line are all starting in the same columns but they are of different lengths.

for example (ccc is the field length and bbb is the blank space),

cbbbbccccbcccccccbbccccccc
bbbbbcccbbccccbbbbbcc
ccccbccccbcccccccbbccc
ccbbbbbbbbbbbbbbbbbc

i hope the alignment is ok after i posted it. the fields in each line start at the same column.

I think Perderabo's solution might solve it. Is it possible to guide me this solution with some sample codes so that I can work on it? I will try with this code and see it works on my data sets.




Sorry, I've just learnt shell programming not long ago on my own so I am not so good. Thanks!

Last edited by ReV; 07-13-2005 at 12:35 AM.
Reply With Quote
  #20  
Old 07-13-2005
ReV ReV is offline
Registered User
 

Join Date: Jun 2005
Posts: 34
Hi,

I have gotten help from another forum and it seems to be the correct method! It shd also be similar to what is being suggested in this thread too! I am pasting the code here so that in future, if someone need the same help, he can refer to this:

PHP Code:
#cutting the required fields
cat $file cut -b 1-13 $TMP/field.1
cat $file 
cut -b 14-44 $TMP/field.2
cat $file 
cut -b 45-75 $TMP/field.3
cat $file 
cut -b 76-88 $TMP/field.4
cat $file 
cut -b 89-97 $TMP/field.5
cat $file 
cut -b 98-108 $TMP/field.6
cat $file 
cut -b 109-119 $TMP/field.7
cat $file 
cut -b 185-189 $TMP/field.8
cat $file 
cut -b 235-245 $TMP/field.9
 
#pasting all fields with ";" as delimiter and removing the trailling spaces
paste -d$TMP/field.[1-9] | sed 's/ *//g' $finalfile 
thanks everyone for the help!

Last edited by ReV; 07-13-2005 at 02:11 AM.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:21 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0