How to insert new line in the data file using the script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to insert new line in the data file using the script
# 1  
Old 08-17-2006
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  
Old 08-17-2006
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 09:35 AM..
# 3  
Old 08-22-2006
Hi,

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

Thanks,
Sona.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to insert data into black column( Secound Column ) in excel (.XLSX) file using shell script?

Source Code of the original script is down below please run the script and try to solve this problem this is my data and I want it column wise 2019-03-20 13:00:00:000 2019-03-20 15:00:00:000 1 Operating System LAB 0 1 1 1 1 1 1 1 1 1 0 1 (5 Replies)
Discussion started by: Shubham1182
5 Replies

2. UNIX for Beginners Questions & Answers

Insert a line of text on nth line of a file

Hi All, I am using UNix Sun OS sun4u sparc SUNW,SPARC-Enterprise My intention is to insert a line of text after 13th line of every file inside a particular directory. While trying to do it for a single file , i am using sed sed '3 i this is the 4th line' filename sed: command garbled: 3... (5 Replies)
Discussion started by: gotamp
5 Replies

3. Shell Programming and Scripting

Script to ingest a csv, validate data and insert into Oracle

Hi all i would appreciate your help... I am looking for a set of unix commands which i can use to 1) ingest a csv file with a known format 2) validate the filename 3) validate the data/datatypes 4) Insert into an oracle db Can you help get me started? yogz888 (1 Reply)
Discussion started by: yogz888
1 Replies

4. Shell Programming and Scripting

How to read a text file line by line and insert into a database table?

I have a test file that I want to read and insert only certain lines into the the table based on a filter. 1. Rread the log file 12 Hours back Getdate() -12 Hours 2. Extract the following information on for lines that say "DUMP is complete" A. Date B. Database Name C.... (2 Replies)
Discussion started by: JolietJake
2 Replies

5. Shell Programming and Scripting

Need help on Insert data to phpMyAdmin mySQL database from Shell Script

Sorry to disturb you, I would like to seek help on inserting data whenever the switch is on or off to my phpMyAdmin mySQL database from my Shell Script. I'm using Raspberry PI as my hardware and I have follow this LINK: instructables.com/id/Web-Control-of-Raspberry-Pi-GPIO/?ALLSTEPS to create my... (4 Replies)
Discussion started by: aoiregion
4 Replies

6. UNIX for Dummies Questions & Answers

How to insert data in a file at last?

Hi Am Using Unix ksh... I have file name called FILE1 Have a content in a FILE as 11/01/2012 12/07/2012 -- -- I have used one variable DATE=12/11/2012 I wants to insert DATE variable value at last line in a file I need Output as cat FILE1 11/01/2012 12/07/2012 -- (2 Replies)
Discussion started by: Venkatesh1
2 Replies

7. UNIX for Dummies Questions & Answers

Bash script to insert data into an html table

hi, I need to create a bash shell script which picks up data from a text file and in the output file puts it into an html made table. I have to use sed and awk utilties to do this the input text file will contain data in the format: job name para1 para2 para3 para4 para4 1 ... (1 Reply)
Discussion started by: intern123
1 Replies

8. Shell Programming and Scripting

insert a header in a huge data file without using an intermediate file

I have a file with data extracted, and need to insert a header with a constant string, say: H|PayerDataExtract if i use sed, i have to redirect the output to a seperate file like sed ' sed commands' ExtractDataFile.dat > ExtractDataFileWithHeader.dat the same is true for awk and... (10 Replies)
Discussion started by: deepaktanna
10 Replies

9. UNIX for Dummies Questions & Answers

Need Script to insert colons in each line of file

I have a file with over 500 MAC addresses. Each address is on a new line. However, the MACs do not have ":" I need a script that will read the file, line by line and insert colons in the addresses and then print the results to a new file. current.txt looks like this 111111111111 222222222222... (4 Replies)
Discussion started by: canopus15
4 Replies

10. Shell Programming and Scripting

sed, insert data from a file to another?

Hello, I have 2 files. File1 has data I wrote, and File2 is a file created by an application. I would like to insert the data from File1 into File2, but it has to be inserted at a certain location on File2. I know I need to search for "</jsp-param> </jsp-descriptor>" But I don't know... (4 Replies)
Discussion started by: ctcuser
4 Replies
Login or Register to Ask a Question