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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
unable Insert data from .dat file to .xls can anybody help me kreddy2003 Shell Programming and Scripting 1 05-28-2008 05:33 AM
How to insert data into MYSql database from a text file shirleyeow Shell Programming and Scripting 4 01-11-2008 05:00 AM
find the position in a file and insert the data there isingh786 HP-UX 5 04-11-2006 09:31 PM
sed, insert data from a file to another? ctcuser Shell Programming and Scripting 4 05-03-2005 01:43 PM
Insert a line as the first line into a very huge file shriek UNIX for Advanced & Expert Users 3 03-09-2005 01:22 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 08-17-2006
Sona Sona is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 13
How to insert new line in the data file using the script

Hi all,

I have a test.dat file.In that file i have many lines of data.
IN between some lines i want to insert a new line while running the test.ksh.

Say for ex:
In the dat file i have data like

N001 100.00
N001 200.00
N001 300.00
N001 400.00 <==
After this line i want to insert line like
N001 1000.00 ( total of all the N001 data).
N002 100.00
N002 200.00
N002 300.00
N002 400.00

Please tell me how i can do this by runnin ga script.

Thanks in Advance,
Sona.
  #2 (permalink)  
Old 08-17-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
nawk -f sona.awk test.dat

sona.awk:
Code:
FNR==1 {f1=$1}
{
   if ( $1 == f1 )
      t+=$2
   else {
     printf("%s%s%.2f\n", f1, OFS, t); f1=$1; t=$2
   }
}
1
END { printf("%s%s%.2f\n", f1, OFS, t) }

Last edited by vgersh99; 08-17-2006 at 08:35 AM..
  #3 (permalink)  
Old 08-22-2006
Sona Sona is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 13
Hi,

Thanks for your response.Can you please explain this piece of code.i could not understand the code.

Thanks,
Sona.
Sponsored Links
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 05:04 PM.


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