Parsing a line in Shell Script | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Parsing a line in Shell Script

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-31-2007
unishiva unishiva is offline
Registered User
 
Join Date: Oct 2007
Last Activity: 30 October 2008, 6:20 PM EDT
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Parsing a line in Shell Script

I have record line somthing like below with first line showing char spacing not real record line
1 | 2 | 3rd Field--------------|-4th field--| This is charcatersapcing of line
DF20000000000000000130.7890000000750

I shoudl get two line from above line
1st line should
1 | 2 | 3rd Field-------------|4th field--| This is charcatersapcing of line
DF125000000000000000000000000000000 Here the second field is (2nd - 4th filed in the above line

2ndst line should
1 | 2 | 3rd Field---------------|-4thfield--| This is charcatersapcing of line
DF075000000000000000130.7890000000000
respective (ie 1 2 3 4) Field lenths in all the records are same
Please let me know what is best way of doing this.

Thanks
uni

Last edited by unishiva; 10-31-2007 at 07:35 PM..
Sponsored Links
    #2  
Old 11-01-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
 
Join Date: Mar 2005
Last Activity: 5 July 2014, 11:14 AM EDT
Location: classification algos
Posts: 3,203
Thanks: 19
Thanked 30 Times in 27 Posts
both the first line and second line looks similar to me

except for the difference in the second line as ".7890000000000"

Is that the only difference you are interested in ?
Sponsored Links
    #3  
Old 11-01-2007
manas_ranjan's Avatar
manas_ranjan manas_ranjan is offline
Registered User
 
Join Date: Jul 2007
Last Activity: 18 April 2014, 7:12 AM EDT
Location: Amsterdam
Posts: 269
Thanks: 11
Thanked 0 Times in 0 Posts
can you please be more appropriate....on the question......with more specific examples of the questions......
    #4  
Old 11-01-2007
unishiva unishiva is offline
Registered User
 
Join Date: Oct 2007
Last Activity: 30 October 2008, 6:20 PM EDT
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Sorry for the confusion

Let me put it simple ..I wanted crate two lines by parsing one lin by exracting certian fields

I have record line somthing like below (Origanal line before Parsing)

DF02000XXYYYY00200.89ZZPPPP00800

Field discription :
DF - FirstField (Character Position 1 to 2)
02000 - Second Field (Characters position 3 to 7)
XX third Field (Characters position 8 to 9)
YYYY Fourth Field (Characters position 10 to 13)
00200.89 fifth Field (Characters position 14 to 21)
ZZ sixth Field (Characters position 22 to 23)
PPPP seventh Field (Characters position 24 to 27)
00800 eightth Field (Characters position 28 to 32)

I wanted to create two new line by parsing above line (each line having again 7 fields)
1st line should loolk line
DF0120000000000000000000000000000
DF - First Field (Same as that of origanal iine)
01200 - Second Field ( This is Difference between 2ndfiled and 8th Field of origanla line)

All other fields are 0's

2nd Line should look like
DF00800XXYYYY00200.89ZZ000000000

DF - First Field (Same as that of origanal iine)
00800 - Second Field ( This is same as that of the 8th Field of Origanal line)
XX - thrid field same as that of origanal line
YYYY - fourth field Same as that of the origanal line
00200.89 - Fifth field same as that of orignal line
All other fields should be zeros

I hope this time it is clear. If you still some clarification .. I will write back.
Thanks for all your help.

Thanks
Uni
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Parsing a command line parameter in script pbmax626 Shell Programming and Scripting 11 08-18-2011 12:44 PM
parsing using shell script LavanyaP Shell Programming and Scripting 5 05-13-2011 06:18 AM
XML parsing using shell script LavanyaP Shell Programming and Scripting 2 05-13-2011 04:25 AM
shell script parsing with sed jjamd64 UNIX for Dummies Questions & Answers 5 12-11-2007 03:51 PM
Parsing text from one line with shell scripts th3g0bl1n UNIX for Dummies Questions & Answers 3 10-19-2007 05:49 AM



All times are GMT -4. The time now is 10:01 AM.