dynamic editing using shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting dynamic editing using shell script
# 1  
Old 05-14-2008
dynamic editing using shell script

Hi,

I would like to edit an input data-file by changing a variable in it
in steps:

For ex: If my input file is 'big.in', then it has the following data:

2.54 0.01 0.5 0.0

My source code then reads this above line, executes and gives out some
output. Then ,
I want to increment the value "0.01" in the above file by some step
and the source code reads it again, executes and gives another output
and so on...

I can use Finding & replacing (ex: 's/0.01/0.02/g') to replace a
previous value, but if there are 100 values I need to substitute, it
becomes cumbersome..there must be a better way, like using a variable
for finding and replacing...

Any help would be appreciated

Thanks
# 2  
Old 05-14-2008
I think you are being a bit vague here as to how much you want to add and to which values, but I'd guess at something like this:
Code:
#!/bin/sh
INC=0.01
while read line
do
  lineout=""
  for num in $line
  do
    num=expr $num + $INC
    if [ -z "$lineout" ]
    then
      lineout=$num
    else
      lineout="$lineout $num"
    fi
  done
  echo "$lineout"
done

(Untested)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Font Editing to be done in shell script

Hi, Iam writing a script in unix shell and need to edit the output (With colors and bold/italic/underline) and send as email. Can someone please help me on this requirement Output as below. Need to know how to set this in echo command Message Flow: messageflow1 //need to put this in red... (7 Replies)
Discussion started by: Anusha M
7 Replies

2. Shell Programming and Scripting

Passing dynamic value to shell script

Hi Team, I'm using HP UX. I want to pass a variable dynamically as input while executing the script and that value need to be replaced with a string in the script. I tired SED, in the command line its working but while I keep the same command in the script its not working. Can someone help me... (4 Replies)
Discussion started by: hazel
4 Replies

3. Shell Programming and Scripting

Shell script dynamic command

I need to run a shell script with dynamic command in it like # Begin script... mysql xx "select * from tab" | sed 's/\t/|/g' > GENERATED_20100304.txt the dynamic part is 20100304 which should be today's date, and it needs to run every day and create a new file with... (2 Replies)
Discussion started by: nuthalapati
2 Replies

4. Shell Programming and Scripting

editing a file using shell script

HI all, I have file in the below format 1111111111_222222222_3333333 111111_22222_33333 11111111_222222_33333333333 i need to display this file like this 2222222_1111111111 22222_11111111 22222222222_1111111111111 can anyone help me with this Thanks in advance (1 Reply)
Discussion started by: saravanan71184
1 Replies

5. Shell Programming and Scripting

Implementing dynamic way of editing fstab

Hey guys, I have some trouble trying to add qualifiers like 'usrquota' & 'grpquota' to a specific field in the fstab through scripts. But im not able to add it to filessystems of my choice. What im trying to do is to prompt the users about what filessystem they want the diskquota... (2 Replies)
Discussion started by: dplate07
2 Replies

6. UNIX for Dummies Questions & Answers

Editing Shell Script

Hi I'm a newbie, but I understand that there's some space difference between unix and the pc, which is why I can't write shell script on my pc but I can view it using notepad, wordpad, etc. Is there any program I can use that will let me view the shell script and edit it without screwing up... (6 Replies)
Discussion started by: qtip
6 Replies

7. Shell Programming and Scripting

editing a file via a shell script ??

Morning All: I know this might be easy but since I don't do this very often I get stumped real quick... Sun box Solaris 8 ksh... I need to edit a file via a shell script. In this file I need to locate one specific line and then remove that line plus the next 20 line below that.... Any... (2 Replies)
Discussion started by: jimmyc
2 Replies

8. Shell Programming and Scripting

creating dynamic shell script

Hello I am trying to create a dynamic ksh script and I have an issue. I have a script a.ksh and it has got the following lines (for example) #!/bin/ksh # trace mode +x : without trace -x : with trace set +xv echo hi, i am going to create a dynamic script now cat >> dynamic.ks <<EOF... (2 Replies)
Discussion started by: sundarkumars
2 Replies

9. Shell Programming and Scripting

Dynamic variables within shell script

Hi Gurus, I have a requirement of writting the shell script where it should ask me two values FND_TOP=/d02/app/oracle/xxx/fnd/11.5.0 CDCRM_TOP=/d02/app/oracle/xxx/cdcrm/11.5.0 and then keep these values stored as variables for the execution of rest of the script. Because, I have to... (2 Replies)
Discussion started by: isingh786
2 Replies

10. UNIX for Dummies Questions & Answers

Editing a file in a shell script

Using Solaris 8. I need to create a shell script that will edit a text file. I need to look in the text file and do a search and replace. For instance, the text file name is always 'filename'. I need to open filename and replace every instance of 'oldtext' with 'newtext'. 'oldtext' is static. ... (3 Replies)
Discussion started by: jowpup
3 Replies
Login or Register to Ask a Question