|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. Code:
2684717 -194.7050476 64.2345581 150.6500092 0 0 2684718 -213.1575623 62.7032242 150.6500092 0 0 *INCLUDE $# filename ./meshes/exportneu/147.k *END mesh.k is as follows Code:
100 or any other 3 digit number I want to replace the 147.k of this input.k to another number from another file mesh.k which is 100 in this case.. Required output is as follows Code:
2684717 -194.7050476 64.2345581 150.6500092 0 0 2684718 -213.1575623 62.7032242 150.6500092 0 0 *INCLUDE $# filename ../meshes/exportneu/100.k *END I used Code:
sed '/\<meshes\>/!d;=;s/.* ([^ ]\+).*/\1/;R mesh.k' input.k | sed 'N;N;s|\n|s/|;s|\n|/|;s|$|/|;q' >temp.sed sed -i -f temp.sed input.k The point is that I want to replace this Quote:
i know it can work with searching the line with word meshes for example and the dividing with last / and piping the data from other file but am not able to formulate the sed or awk. I hope now you people understand what I mean. regards Last edited by hamnsan; 06-12-2012 at 07:44 AM.. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Please post the required data from "mesh.k" and "input.k".
Also, please edit your post and use code tags. (hurry up, our mods here, are too fast ) |
| The Following 2 Users Say Thank You to clx For This Useful Post: | ||
hamnsan (06-12-2012), Scrutinizer (06-12-2012) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
hi experts,
I have updated the question.. any suggestions or comments. Last edited by hamnsan; 06-12-2012 at 10:42 AM.. |
|
#4
|
||||
|
||||
|
Assuming that mesh.k contains only 1 number: Code:
awk 'NR==FNR{num=$1;next} /[0-9]{1,}\.k$/ {sub("[0-9]{1,}\.k$",num".k")} {print}' mesh.k input.k |
| The Following User Says Thank You to elixir_sinari For This Useful Post: | ||
hamnsan (06-13-2012) | ||
| Sponsored Links | ||
|
![]() |
| Tags |
| awk, linux, replace, sed |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Replace line in file with line in another file based on matching string | luckycharm | Shell Programming and Scripting | 5 | 01-09-2012 11:16 PM |
| replace (sed?) a single line/string in file with multiple lines (string) from another file?? | tuathan | Shell Programming and Scripting | 5 | 04-20-2011 12:16 AM |
| To trim Certain field in a line of a file and replace the new string in that position | rpadhi | Shell Programming and Scripting | 4 | 08-15-2009 11:03 AM |
| Replace string in a file within a range of line | tosattam | Shell Programming and Scripting | 3 | 08-15-2008 01:12 AM |
| how can search a String in one text file and replace the whole line in another file | kkraja | UNIX for Dummies Questions & Answers | 6 | 08-06-2008 07:23 AM |
|
|