First run overwrite then append


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting First run overwrite then append
# 1  
Old 02-21-2014
First run overwrite then append

I'm overwriting .unl in first run and after that in seq. runs appending by following method. Any other method or command can do it easier?

Code:
ARY_VALUE=1
while [ $ARY_VALUE -lt 99 ]
do
 
  if [ $ARY_VALUE-eq 1 ]; then
  type.sql > out.unl 
  else 
  type.sql >>out.unl 
  fi 
  ARY_VALUE--;
 
done

# 2  
Old 02-21-2014
Quote:
Originally Posted by Roozo
I'm overwriting .unl in first run and after that in seq. runs appending by following method. Any other method or command can do it easier?

Code:
ARY_VALUE=1
while [ $ARY_VALUE -lt 99 ]
do
 
  if [ $ARY_VALUE-eq 1 ]; then
  type.sql > out.unl 
  else 
  type.sql >>out.unl 
  fi 
  ARY_VALUE--;
 
done

To make your current script work, you need a space between $ARY_VALUE and -eq; and ARY_VALUE-- isn't valid in most shells. Try this instead:
Code:
ARY_VALUE=1
> out.unl
while [ $ARY_VALUE -lt 99 ]
do 
  type.sql >> out.unl  
  ((ARY_VALUE++))
done

# 3  
Old 02-21-2014
Thanks, I was in c and used decrement by mistake.
# 4  
Old 02-21-2014
How about
Code:
while [ $A -lt 99 ]; do type.sql; ((A++)); done >out.unl

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Python script to run multiple command and append data in output csv file

Experts, I am writing a script and able to write only small piece of code and not able to collect logic to complete this task. In input file have to look for name like like this (BGL_HSR_901_1AG_A_CR9KTR10) before sh iss neors. Record this (BGL_HSR_901_1AG_A_CR9KTR10) in csv file Now have to... (0 Replies)
Discussion started by: as7951
0 Replies

2. Shell Programming and Scripting

Loop overwrite first input

function one { echo "Who is here?" read name   echo "Who old are you $name?" read age if ; then Sam="$age" else Sam="26" fi   if ; then Jack="$age" else Jack="49"... (4 Replies)
Discussion started by: samsan
4 Replies

3. Shell Programming and Scripting

Better to Delete or Overwrite

Hello All, I had just a question about my Bash Script I'm currently writing. The script I have writes some text to a output file. After I write to the output file I send the file to another server to do some stuff with it. After the file sends in the script, I don't need the output/txt... (4 Replies)
Discussion started by: mrm5102
4 Replies

4. Programming

[Solved] Append instead of overwrite

Hi, I have a script which append the .csv file which already exist but in my scenarion every time instead of appending the contect it overwrite the file and creating new .csv file. SET ORAUSR=ops$371664 SET ORAPWD=Oracle12345 SET ORADB=orcl SET DBCON=%ORAUSR%/%ORAPWD%@%ORADB% sqlplus... (1 Reply)
Discussion started by: tushar_spatil
1 Replies

5. Shell Programming and Scripting

Need to append columns for every run

Hi, I have a requirement where I need to append the runtimes of the jobs for every run. I have some 100 jobname and it will be static in output(1st column) . Everyday I need to run my script to find the runtimes for that day and add the entire 100 runtimes to the right of those 100 jobs(2nd... (19 Replies)
Discussion started by: ajayakunuri
19 Replies

6. UNIX for Dummies Questions & Answers

overwrite problem

my script is: awk '...mycode...' file1.txt > file2.txt and i want to overwrite file2.txt eachtime I run this script. but it says:File exists! :( I have tried awk '...mycode...' file1.txt >| file2.txt but it again says:Missing name for redirect! :confused::confused: what is this? (2 Replies)
Discussion started by: gc_sw
2 Replies

7. UNIX for Dummies Questions & Answers

Output to file but append rather than overwrite?

I am running a command which has a parameter that outputs the results to a file each time it is run. Here is the command: --fullresult=true > importlog.xml Can I add the output to the file rather than creating a new one which overwrites the existing one? If not can I make the file name... (2 Replies)
Discussion started by: Sepia
2 Replies

8. UNIX for Dummies Questions & Answers

overwrite problem

Hi im using the following to copy a file to a directory, the user being prompted to overwrite if the file already exists in that directory, cp -i myfile /home/brief/bin2 but this reveals the path of the directory when being prompted to overwrite (below) cp: overwrite... (2 Replies)
Discussion started by: ali999
2 Replies

9. UNIX for Dummies Questions & Answers

Overwrite

if i want to pipe output to a file, say, cat abc.dat > abc.txt, how do i make it replace the existing file? (9 Replies)
Discussion started by: Duckman
9 Replies
Login or Register to Ask a Question