Sponsored Content
Top Forums Shell Programming and Scripting sed or awk to replace a value in a certain line. Post 302603259 by hamnsan on Wednesday 29th of February 2012 11:33:56 AM
Old 02-29-2012
sed or awk to replace a value in a certain line.

I have an input like following.
Code:
  *DEFINE_CURVE_TITLE 
Force for tool binder 
$#    lcid       sidr       sfa        sfo              offa                   offo      dattyp 
          3              0     1 .000000   125.00000       0.000     0.000         0 
$#                a1                  o1
 0.000               0.000 
       0.5000000          -1.0000000 
     100.0000000          -1.0000000

I want to modify the 3rd line after *DEFINE_CURVE_TITLE like
3 0 1.000000 107.00000 0.000 0.000 0

so that it becomes
Code:
  *DEFINE_CURVE_TITLE 
Force for tool binder 
$#    lcid       sidr       sfa        sfo              offa                   offo      dattyp 
          3              0     1 .000000   107.00000       0.000     0.000         0 
$#                a1                  o1
 0.000               0.000 
       0.5000000          -1.0000000 
     100.0000000          -1.0000000

The question is that I can search for the required line as follows
Code:
  sed -i -e '/^\**DEFINE_CURVE_TITLE/{n;n;n;R $4 newBHF.txt' -e 'd}' input.txt

This way I am on the line to be edit i.e. three lines below the search string.
Now I have to change the values of $4 from 125.00000 to someother value that could be taken from newBHF.txt. That newBHF.txt has the required replacement i.e only one value 107.00000 . If possible please also tell me how can I set $4 , if I have the value in another variable in the same program.
This will help to do alot of things myself. Smilie

best regards


Moderator's Comments:
Mod Comment Please use next time
code tags for your code and data

Last edited by vbe; 02-29-2012 at 12:57 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace part of a line with sed/awk

Hello I have a document and in this document I have several occurrence of "VAR == xxxxxxx" and xxxxx can be anything. I don't know what it is. I want to replace the 'xxxxx's with something I know. What I know however, is the line numbers of the VAR =='s in the file. How can I replace... (1 Reply)
Discussion started by: alirezan
1 Replies

2. Shell Programming and Scripting

Replace specific field on specific line sed or awk

I'm trying to update a text file via sed/awk, after a lot of searching I still can't find a code snippet that I can get to work. Brief overview: I have user input a line to a variable, I then find a specific value in this line 10th field in this case. After asking for new input and doing some... (14 Replies)
Discussion started by: crownedzero
14 Replies

3. Shell Programming and Scripting

Replace line and field using SED and/or AWK or some other suggestion

QUESTION 1: How do you replace a specific line (i.e. line 4) with a new user defined line (i.e. the contents of SAMS’s name, history, math and English grades have been set already). I have been attempting to use SED (FYI: I don’t have GNU SED) or AWK, but haven’t had any luck. FYI: I am using... (1 Reply)
Discussion started by: thibodc
1 Replies

4. Shell Programming and Scripting

sed or awk to replace a value in a certain line containing a string

hi experts , I have an input like following. R sfst 1000.0000 $ new time step for mass scaled calculation R dt2ms -4.000E-7 $ friction value for blank R mue ... (10 Replies)
Discussion started by: hamnsan
10 Replies

5. Shell Programming and Scripting

sed or awk to replace a value in a certain line from another file containing a string

Hi experts, In my text file I have the following alot of lines like below. input.k is as follows. 2684717 -194.7050476 64.2345581 150.6500092 0 0 2684718 -213.1575623 62.7032242 150.6500092 0 0 *INCLUDE $# filename... (3 Replies)
Discussion started by: hamnsan
3 Replies

6. Shell Programming and Scripting

I need to know how to replace a line after a pattern match with an empty line using SED

Hi How Are you? I am doing fine! I need to go now? I will see you tomorrow! Basically I need to replace the entire line containing "doing" with a blank line: I need to the following output: Hi How Are you? I need to go now? I will see you tomorrow! Thanks in advance.... (1 Reply)
Discussion started by: sags007_99
1 Replies

7. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

8. Shell Programming and Scripting

Multiple line search, replace second line, using awk or sed

All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed... I have an input file similar to: &LOG &LOG Part: "@DB/TC10000021855/--F" &LOG &LOG &LOG Part: "@DB/TC10000021852/--F" &LOG Cloning_Action: RETAIN &LOG Part: "@DB/TCCP000010713/--A" &LOG &LOG... (5 Replies)
Discussion started by: KarmaPoliceT2
5 Replies

9. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

10. Shell Programming and Scripting

Replace values in script reading line by line using sed

Hi all, Let's say I have a script calling for the two variables PA_VALUE and PB_VALUE. for pa in PA_VALUE blah blah do for pb in PB_VALUE blah blah do I have a text file with two columns of values for PA and PB. 14.5 16.7 7.8 9.5 5.6 3.6 etc etc I would like to read this... (7 Replies)
Discussion started by: crimsonengineer
7 Replies
All times are GMT -4. The time now is 01:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy