Replacing data of output file with input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing data of output file with input
# 8  
Old 01-29-2009
I took your point to note and i did little home work.... Comm command compares 2 files... i just dont want comparsion.... actually what i want is replacing....
ie for example... in time.out file there is alread data for date 25 now read.out again got 25.... i want to replace the data of 25 in time.out with runtime.out irrespective of there being any change in the data... and if there is no 25 in time.out then write it .... thats excatly what i want....Please say me that there some way i can do this and help me out... please....
# 9  
Old 01-29-2009
If I understand your question correctly, you want to search for the date in time.out and if it is present, update it with the line from runtime.out or append to time.out, you may try the below code:
Code:
tr -d '\n' < runtime.out >temp.out
grep -q $CUR_MAINT_DATE time.out
if [ $? -eq 0 ]
   echo |cat time.out -|sed "s/^$CUR_MAINT_DATE.*/`cat temp.out`/"|awk '{ if( NR==1 ) printf $0; else printf "\n" $0; }'
else
  #append code
fi

This may be easier if you can have newline at the end of time.out file:
Code:
sed "s/^$CUR_MAINT_DATE.*/`cat temp.out`/" time.out

# 10  
Old 01-29-2009
The code you gave almost work but there one problem....
i added appened and then to if and the code is like this....
Code:
read.ksh `basename ${0}` $1 $2 ${CUR_MAINT_DATE} > runtime.out
tr -d '\n' < runtime.out >temp.out
grep -q $CUR_MAINT_DATE time.out
if [ $? -eq 0 ]
then
   echo |cat time.out -|sed "s/^$CUR_MAINT_DATE.*/`cat temp.out`/"|awk '{ if( NR==1 ) printf $0; else printf "\n" $0; }'
else
  tr -d '\n' < runtime.out >> time.out;echo >> time.out
fi

Actually read.ksh is called by Mail.ksh
when i run Mail.ksh i get output like this
Code:
 ./Mail.ksh 1 1
Current maintenance date is 20090126
20090124,00:02:26,00:04:19,86752,00:01:37,00:02:50,01:07:52,150818, ,
20090125,00:02:31,00:00:11,2776,00:01:38,00:01:31,00:56:36,108938, ,
20090126,00:02:33,00:00:35,8187,00:01:42,00:01:32,02:02:08,321055, ,
20090127,00:02:33,00:03:04,62153,00:01:39,00:02:25,01:39:55,266355, ,
Current maintenance date is 20090127
20090124,00:02:26,00:04:19,86752,00:01:37,00:02:50,01:07:52,150818, ,
20090125,00:02:31,00:00:11,2776,00:01:38,00:01:31,00:56:36,108938, ,
20090126,00:02:33,00:00:35,8187,00:01:42,00:01:32,02:02:08,321055, ,
20090127,00:02:33,00:03:04,62153,00:01:39,00:02:25,01:39:55,266355, ,
Current maintenance date is 20090128

where i have to get like this
Code:
 ./Mail.ksh 1 1
Current maintenance date is 20090126
Current maintenance date is 20090127
Current maintenance date is 20090128

where all the curent ma... statement is comming becaue i have an echo... which i will remove later...
Ofcose its working as it is appeneding a new line to my time.out at the end ie 28... but i dont know if its replaceing 26 and 27 in time.out... as they are same...for time being...i will test that later with more data...
But please help me in removing this print or echo statement thats comming when i execute the script

Thanks

Bhagya
# 11  
Old 01-29-2009
I made few changes and i got the result as i want.... Thanks a lot for being there for me
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to reformat output if input file is empty, but not if file has data in it

The below awk improved bu @MadeInGermany, works great as long as the input file has data in it in the below format: input chrX 25031028 25031925 chrX:25031028-25031925 ARX 631 18 chrX 25031028 25031925 chrX:25031028-25031925 ARX 632 14... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

Awk replacing file with user input

this section of the awk code i have here takes file to work with from the user. the user specifies the file name from the command line and the file name is assigned to the variable $FLIST awk 'BEGIN { while((getline < "'${FLIST}'")>0) S FS="\n"; RS="}\n" } now, i dont want... (5 Replies)
Discussion started by: SkySmart
5 Replies

3. Shell Programming and Scripting

Replacing data in one file with data in another

Hello, I have 2 files delimited by "|". File1: 1|New York 12| Buffalo 599| Syracuse File2: 56 Kennedy |1 9 Burridge Pl|15 98 BELL ROCK |599 My goal: Is to replace the numerical numbers in "File 2" (second field, not street address) with the corresponding city names from... (2 Replies)
Discussion started by: vestport
2 Replies

4. Shell Programming and Scripting

adding data in input file if 2nd script output SUCCESS

Hi All, how can i edit my original data and add more data if my 2nd script outputs SUCESS? ex. input file: 1.txt nik,is,the 1script.sh if 2ndscript.sh output SUCCESS then i'm going to edit my input file and add data best,pogi.. sample outputdata. nik,is,the,best,pogi 2ndscript.sh... (3 Replies)
Discussion started by: nikki1200
3 Replies

5. Shell Programming and Scripting

split input data file and put into same output file

Hi All, I have two input file and need to generate a CSV file. The existing report just "GREP" the records with the Header and Tailer records with the count of records. Now i need to split the data into 25 records each in the same CSV file. id_file (Input file ) 227050994 232510151... (4 Replies)
Discussion started by: rasmith
4 Replies

6. Shell Programming and Scripting

How to add data from 2 input files and save it in 1 output file

Hi, i have 2 input files which are file1.txt and file2.txt. I need to extract data from file1.txt and file2.txt and save it in file3.txt like example below:- File1.txt ID scrap1 Name scrap1 start 1 end 10 ID scrap2 Name scrap2 start 11 end ... (4 Replies)
Discussion started by: redse171
4 Replies

7. Shell Programming and Scripting

Dynamic output file generation using a input text file with predefined output format

Hi, I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format. Example: File.txt AP|{SSHA}VEEg42CNCghUnGhCVg== APVG3|{SSHA}XK|"password" AP3|{SSHA}XK|"This is test" .... etc --------- test.sh has... (1 Reply)
Discussion started by: hudson03051nh
1 Replies

8. Shell Programming and Scripting

Need script to take input from file, match on it in file 2 and input data

All, I am trying to figure out a script to run in windows that will allow me to match on First column in file1 to 8th Column in File2 then Insert file1 column2 to file2 column4 then create a new file. File1: 12345 Sam 12346 Bob 12347 Bill File2:... (1 Reply)
Discussion started by: darkoth
1 Replies

9. UNIX for Dummies Questions & Answers

Replacing part of a text file with user input.

Ok, I am brand new to UNIX and I am trying to learn a cross between basic script and database use. I had got some ideas off the net on simple ideas for learning UNIX. I am working on creating a simple phone book program that allows myself to enter our employees from work into a phone book text... (0 Replies)
Discussion started by: georgefurbee
0 Replies

10. Shell Programming and Scripting

replacing spaces with null or 0 in the input file

hi i have records in my input file like this aaa|1234||2bc||rahul|tamilnadu bba|2234||b4c||bajaj|tamilnadu what i am expecting is in between two pipes if there is no character it should be replaced with null or 0 so my file will look like this aaa|1234|null|2bc|0|rahul|tamilnadu... (4 Replies)
Discussion started by: trichyselva
4 Replies
Login or Register to Ask a Question