Sponsored Content
Top Forums Shell Programming and Scripting sed or awk to replace a value in a certain line from another file containing a string Post 302654685 by hamnsan on Tuesday 12th of June 2012 07:11:45 AM
Old 06-12-2012
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:
147.k to 100.k where 100
is written in another file mesh.k , like in the other file only 100 is present or it could be 3 digit anyother number.
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 08:44 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed conditional string replace for each line

Hi all, I appreciate the enormous amount of knowledge that flows in this forum. I am an average UNIX user. I have many files with lines like the below. I have separated each line with space for ease of reading. I need to replace the first occurance of "/00" with null on those lines that have... (6 Replies)
Discussion started by: Nanu_Manju
6 Replies

2. Shell Programming and Scripting

Appending string (charachters inside the line) to a fixed width file using awk or sed

Source File: abcdefghijklmnop01qrstuvwxyz abcdefghijklmnop02qrstuvwxyz abcdefghijklmnop03qrstuvwxyz abcdefghijklmnop04qrstuvwxyz abcdefghijklmnop05qrstuvwxyz Whatever characters are in 17-18 on each line of the file, it should be concatenated to the same line at the character number... (6 Replies)
Discussion started by: tamahomekarasu
6 Replies

3. Shell Programming and Scripting

How to find a certain string in a file and replace it with a value from another file using sed/awk?

Hi Everyone, I am new to this forum and new to sed/awk programming too !! I need to find particular string in file1(text file) and replace it with a value from another text file(file2) the file2 has only one line and the value to be replaced with is in the second column. file 1: (assert (=... (21 Replies)
Discussion started by: paramad
21 Replies

4. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies

5. Shell Programming and Scripting

sed: how to replace string by another line

hi experts, i would like to do some html-file replacements and encounter the following problem: after cleaning up the file a bit i'd like to replace a regex with a reference and the content of another line. example: /<title>\(*\) - Wikipedia<\/title>/ should be replaced by \1 (the title... (2 Replies)
Discussion started by: chrisnie
2 Replies

6. 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

7. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 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

Replace string in XML file with awk/sed with string from another

Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file: </member> <member> <name>TransactionID</name> <value><string>123456789123456</string></value> </member> <member> <name>Number</name> ... (9 Replies)
Discussion started by: cozzin
9 Replies

10. Shell Programming and Scripting

Replace string of a file with a string of another file for matches using grep,sed,awk

I have a file comp.pkglist which mention package version and release . In 'version change' and 'release change' line there are two versions 'old' and 'new' Version Change: --> Release Change: --> cat comp.pkglist Package list: nss-util-devel-3.28.4-1.el6_9.x86_64 Version Change: 3.28.4 -->... (1 Reply)
Discussion started by: Paras Pandey
1 Replies
mcv(1)							       Scotch user's manual							    mcv(1)

NAME
mcv - mesh file converter SYNOPSIS
mcv [options] [imfile] [omfile] [oxfile] DESCRIPTION
The mcv program converts Scotch mesh files from and to other external file formats. File imfile is converted into mesh file omfile, with optional geometry data being put in geometry file oxfile, if it is available. When file names are not specified, data is read from standard input and written to standard output. Standard streams can also be explicitly represented by a dash '-'. When the proper libraries have been included at compile time, mcv can directly handle compressed meshes, both as input and output. A stream is treated as compressed whenever its name is postfixed with a compressed file extension, such as in 'brol.msh.bz2' or '-.gz'. The compres- sion formats which can be supported are the bzip2 format ('.bz2'), the gzip format ('.gz'), and the lzma format ('.lzma', on input only). OPTIONS
-h Display some help. -iifmt Set format of input mesh file, which can be: bnum Boeing-Harwell format. This is an elemental matrix format. Only square matrices are supported. In case the file contains sev- eral matrices, the num parameter allow the user to provide the index of the matrix to convert, starting from 0. When the num parameter is not set, it is assumed to be 0. s Scotch mesh format. -oofmt Set format of output mesh file, which can be: s Scotch mesh format. This is the only possible choice at the time being. -V Display program version and copyright. EXAMPLE
Convert a Harwell-Boeing elemental mesh into a Scotch mesh. $ mcv -ib brol.hb brol.msh SEE ALSO
mtst(1), mord(1). Scotch user's manual. AUTHOR
Francois Pellegrini <francois.pellegrini@labri.fr> February 14, 2011 mcv(1)
All times are GMT -4. The time now is 08:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy