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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Passing the values to the secondary script when it invoked by primary script venu_eie UNIX for Advanced & Expert Users 2 07-03-2008 08:10 AM
Passing the values to the secondary script when it invoked by primary script venu_eie Shell Programming and Scripting 1 07-03-2008 07:16 AM
create a shell script that calls another script and and an awk script magikminox Shell Programming and Scripting 0 06-26-2008 03:50 AM
help me in sending parameters from sqlplus script to unix shell script Hara Shell Programming and Scripting 2 01-29-2008 03:31 PM
Shell Script: want to insert values in database when update script runs ring Shell Programming and Scripting 1 10-25-2007 04:06 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-15-2008
naoseionome naoseionome is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 13
awk script

Hi,

I'm trying to complete the information in a file, it will be my first AWK script and i have no idea how to do that!
I just get the book sed awk - 2nd edition, By Dale Dougherty & Arnold Robbins to try to understand what I have to do, but if someone can help me in the meanwhile I would be very appreciated!

I have this file:


Code:

Line 1-Object Class = common
Line 2-var1,var2,var3,var4,var5,var6,var7,var8,var9,var10,var11,var12,var13,var14,var15,var16,var17,var18,var19,var20,var21,var22,var23,var24,var25
Line 3-123,dfd,common,32434,34,34,23,true,true,0,0,0|0,0,0,0,0,0,FALSE,23,23,1,,,,
Line 4-,,,,,,,,,,,,,,,,,,,12 00 00 00 00 01 |0,,,,,
Line 5-342,dfd,common,32434,34,34,23,true,true,0,0,0|0,0,0,0,0,0,FALSE,23,23,1,,,, 
…

I need to do the following:
-Where I have lines line number 4 I have to write the previous value that was redden from field var1.
- I have to start each line with one hardcoded value.
Output file for this situation:


Code:

Line 1-Object Class = common
Line 2-Identifier,var1,var2,var3,var4,var5,var6,var7,var8,var9,var10,var11,var12,var13,var14,var15,var16,var17,var18,var19,var20,var21,var22,var23,var24,var25
Line 3-001,123,dfd,common,32434,34,34,23,true,true,0,0,0|0,0,0,0,0,0,FALSE,23,23,1,,,,
Line 4-001,123,,,,,,,,,,,,,,,,,,,12 00 00 00 00 01 |0,,,,,
Line 5-001,342,dfd,common,32434,34,34,23,true,true,0,0,0|0,0,0,0,0,0,FALSE,23,23,1,,,, 
…

After doing this I have another thing to do:
- I must gather this file with others similar (also with var1 on the same position) to this one and order the lines by the field Var1.

Second file after being changed will be like:

Code:

Line 1-Object Class = common
Line 2-Identifier,var1,var2,var3,var4,var5,var6,var7,var8,var9,var10,var11,var12,var13,var14,var15,var16,var17,var18,var19,var20,var21,var22,var23,var24,var25
Line 3-002,123,dfd,common,22,1,1,1,false,true,0,0,0|0,0,0,0,0,0,FALSE,23,23,1,,,,
Line 4-002,123,,,,,,,,,,,,,,,,,,,16,,,,,
Line 5-002,342,dfd,common,22,1,1,1,false,true,0,0,0|0,0,0,0,0,0,FALSE,23,23,1,,,,
…

the result that I need is this:

Code:

Line 1-Object Class = common
Line 2-var1,var2,var3,var4,var5,var6,var7,var8,var9,var10,var11,var12,var13,var14,var15,var16,var17,var18,var19,var20,var21,var22,var23,var24,var25
Line 3-123,dfd,common,32434,34,34,23,true,true,0,0,0|0,0,0,0,0,0,FALSE,23,23,1,,,,
Line 4-,,,,,,,,,,,,,,,,,,,12 00 00 00 00 01 |0,,,,,
Line 5-342,dfd,common,32434,34,34,23,true,true,0,0,0|0,0,0,0,0,0,FALSE,23,23,1,,,, 
…

I need to do the following:
-Where I have lines line number 4 i have to write the previous value that was redden from field var1.
- I have to start each line with one hardcoded value.
Output file for this situation:


Code:

Line 1-Object Class = common
Line 2-Identifier,var1,var2,var3,var4,var5,var6,var7,var8,var9,var10,var11,var12,var13,var14,var15,var16,var17,var18,var19,var20,var21,var22,var23,var24,var25
Line 3-001,123,dfd,common,32434,34,34,23,true,true,0,0,0|0,0,0,0,0,0,FALSE,23,23,1,,,,
Line 4-001,123,,,,,,,,,,,,,,,,,,,12 00 00 00 00 01 |0,,,,,
Line 5-001,342,dfd,common,32434,34,34,23,true,true,0,0,0|0,0,0,0,0,0,FALSE,23,23,1,,,, 
…

After doing this I have other thing to do:
- I must gather this file with others similar (also with var1 on the same position) to this one and order the lines by the field “ Var1” and after doing this I will also try to order by the field “Identifier”.
Second file after being changed will be like:

Code:
001,123,dfd,common,32434,34,34,23,true,true,0,0,0|0,0,0,0,0,0,FALSE,23,23,1,,,,
002,123,dfd,common,22,1,1,1,false,true,0,0,0|0,0,0,0,0,0,FALSE,23,23,1,,,,
001,123,,,,,,,,,,,,,,,,,,,12 00 00 00 00 01 |0,,,,,
002,123,,,,,,,,,,,,,,,,,,,16,,,,,
001,342,dfd,common,32434,34,34,23,true,true,0,0,0|0,0,0,0,0,0,FALSE,23,23,1,,,, 
002,342,dfd,common,22,1,1,1,false,true,0,0,0|0,0,0,0,0,0,FALSE,23,23,1,,,,
…

-I must discard lines:

Code:
Object Class = common
Identifier,var1,var2,var3,var4,var5,var6,var7,var8,var9,var10,var11,var12,var13,var14,var15,var16,var17,var18,var19,var20,var21,var22,var23,var24,var25

If they exist in the beginning of the file;

best regards,
Ricardo Tomás
  #2 (permalink)  
Old 09-16-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
It's difficult to make sense of your post... I think you need to edit it and remove some duplicate information?

What have you tried so far.... where are you stuck?
Closed Thread

Bookmarks

Tags
awk, script

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 06:36 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