Referencing file for values and referencing another file to replace values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Referencing file for values and referencing another file to replace values
# 1  
Old 10-11-2013
Referencing file for values and referencing another file to replace values

Hi

I have a file which has values in each line:

Code:
MP304,d40000
MP310,ff0000

etc

I have another file which as the first value in it and is unique in the file(not repeated). I need to replace a string with the second value above. The second file contents is as followsSmiliesnippet)

Code:
<g
         transform="translate(-312.51946,80.94618)"
         id="MP302"
         style="fill:#ff0000;fill-opacity:1">
        <title
           id="title4028">Msukaligwa</title>
        <path
           d="m 1282,344 1,-1 1,0 1,0 3,0 1,0 1,0 1,0 1,1 1,1 -1,2 -1,0 1,0 0,1 1,0 0,1 1,1 0,1 -2,0 -2,0 0,1 -1,0 0,1 1,3 0,1 1,1 -1,1 -2,1 -1,0 -1,1 -1,-1 0,-1 -1,0 -1,-1 -1,0 -1,0 -1,0 -1,0 -1,0 -1,0 0,1 -1,0 -1,1 -1,0 -1,1 -1,0 0,1 -1,0 1,1 1,1 1,1 0,1 1,0 0,1 1,0 1,1 1,0 1,0 2,0 1,0 0,1 -1,0 -1,0 -1,0 -1,1 0,1 0,1 -1,0 1,0 0,1 -1,0 0,1 -1,0 0,1 0,-1 0,1 -1,0 -1,0 -1,0 0,1 -1,0 -1,0 1,0 0,1 -1,0 -1,0 -1,0 -1,0 -1,0 -1,0 0,1 0,-1 0,1 -1,0 -1,0 -1,0 -1,0 -1,0 0,1 0,1 -1,2 -1,0 -2,0 -2,0 -1,0 -1,0 -1,0 -2,0 0,1 0,1 1,1 -1,0 -1,0 -1,-2 -1,0 -1,0 0,-1 0,-1 -1,0 0,-2 2,-1 -1,-1 -1,-2 -1,1 -2,-2 -2,0 0,-1 -1,0 0,1 -1,0 -1,-1 -1,0 -1,0 -1,1 0,1 -1,2 0,1 -1,0 -1,0 -1,0 0,1 -1,0 0,1 0,-1 0,1 -1,0 0,-1 0,1 -1,0 0,-1 0,1 -1,0 0,-1 -1,0 0,1 1,0 -1,0 0,1 1,0 -1,0 -1,0 0,-1 -1,0 0,-1 1,-1 0,-1 0,-1 0,-1 0,-1 0,-1 1,0 0,-1 0,-1 0,-1 1,-1 -1,0 -1,1 -1,0 -1,0 -1,0 -1,-1 -1,0 -1,0 -1,0 -1,0 -2,0 -1,0 -1,-1 -1,0 -1,0 -1,0 0,-1 -1,0 0,-1 0,-1 0,-1 0,-1 0,-1 0,-2 -1,0 -1,0 0,-1 1,0 0,-1 0,-1 0,-1 0,-1 0,-1 -1,0 -1,-1 -1,0 -1,0 -1,0 0,-1 -1,-1 -1,-1 -1,0 0,-1 -1,0 0,-1 1,0 1,-2 -1,0 -1,0 -1,0 -1,0 -1,0 0,-1 0,-1 0,-1 0,-1 1,0 1,0 1,0 1,0 0,-1 1,-1 1,0 -1,-1 2,0 1,0 1,0 0,-1 1,0 1,0 1,0 1,0 1,0 1,0 2,-1 1,0 0,-1 1,-1 2,1 1,1 0,-1 2,-1 1,-1 1,0 0,1 1,1 0,1 1,1 0,-1 1,-1 1,0 1,0 1,0 1,0 1,0 1,0 1,0 1,1 1,0 0,1 1,-1 1,0 0,-1 1,0 0,-1 2,0 0,-1 1,0 1,1 1,0 2,0 0,1 1,0 1,0 1,0 1,0 0,1 0,1 0,1 1,0 1,-1 1,-1 1,-2 0,1 1,0 1,0 1,-1 1,0 2,0 2,-1 1,-1 0,1 1,1 0,1 1,0 1,-1 -1,-1 1,-2 2,1 1,1 1,0 1,0 3,2 1,1 1,0 1,0 1,0 1,-1 1,0 1,0 1,0 1,-1 1,0 0,1 1,1 1,2 0,1 0,-1 0,1 0,-1 0,1 -1,2 0,2"
           id="path446"
           style="fill:#ff0000;fill-opacity:1" />
      </g>
      <g
         transform="translate(-312.51946,80.94618)"
         id="MP303"
         style="fill:#d40000;fill-opacity:1">
        <title
           id="title4034">Mkhondo </title>
        <path
           d="m 1279,409 -2,0 -1,0 -1,0 -1,0 -1,0 -1,1 -1,0 -1,1 -2,1 -1,0 -1,0 0,-1 0,1 -1,0 -1,0 -1,-1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0 0,1 -1,0 0,-1 -1,0 0,1 -1,0 -1,0 -1,0 0,1 0,-1 -1,0 0,1 -1,0 0,-1 0,-1 -1,0 0,-1 0,-1 0,-1 -1,0 -1,0 -1,0 0,1 -1,0 0,-1 -1,0 0,1 0,1 0,1 0,-1 0,1 -1,0 0,1 0,-1 -1,0 -1,0 0,1 0,-1 1,0 -1,0 0,-1 0,1 -1,0 0,-1 0,-1 -1,0 0,1 0,-1 0,-1 0,1 -1,0 -1,0 0,1 0,-1 -1,0 0,-1 1,0 -1,0 0,-1 0,1 -1,0 0,-1 -1,0 -1,0 0,-1 -1,0 -1,0 -1,1 -1,0 -1,0 -1,0 -1,1 -1,0 0,1 -1,0 -1,0 -1,0 0,1 -1,0 0,-1 -1,0 -1,0 0,-1 0,-1 -1,0 -1,-1 2,-2 -1,-1 1,0 1,-2 0,-1 1,-1 1,-1"
           id="path449"
           style="fill:#d40000;fill-opacity:1" />
      </g>
      <g
         transform="translate(-312.51946,80.94618)"
         id="MP304"
         style="fill:#d40000;fill-opacity:1">
        <title
           id="title4040">Pixley Ka Seme</title>
        <path
           d="m 1265,400 1,1 -1,0 0,2 0,1 -1,1 -1,0 -1,0 -1,0 -1,1 -1,1 1,0 1,1 0,1 -1,1 1,0 1,0 1,1 1,1 1,0 1,0 0,-1 0,1 1,0 1,0 2,-1 1,-1 1,0 1,-1 1,0 1,0 1,0 1,0 2,0 -1,1 -1,1 0,1 -1,2 -1,0 1,1 -2,2 1,1 1,0 0,1 0,1 -1,0 -1,0 0,-1 -1,0 0,1 -1,0 -1,0 0,1 0,-1 0,1 -1,0 0,-1 0,1 -1,0 0,-1 -1,0 0,-1 0,-1 0,-1 0,-1 -1,0 -1,0 0,1 0,-1 -1,0 -1,0 -1,0 1,0 0,1 0,1 -1,0 0,1 -1,0 -1,0 -1,-1 0,1 -1,0 0,1 -1,0 -1,0 0,1 0,1 0,1 0,1 -1,0 -1,0 -1,0 0,1 -1,0 0,-1 0,-1 -1,0 -1,0 -1,0 0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 -1,0 1,0 -1,0 0,-1 1,0 0,1 1,0 1,0 -1,0 0,-1 1,0 -1,0 0,-1 1,0 0,1 1,0 0,-1 0,1 1,0 0,-1 0,1 1,0 0,-1 0,1 0,-1 1,0 0,-1 1,0 1,0 1,0 0,-1 1,-2 0,-1 1,-1 1,0 1,0 1,1 1,0 0,-1 1,0 0,1 2,0 2,2 1,-1 1,2 1,1 -2,1 0,2 1,0 0,1 0,1 1,0 1,0 1,2 1,0 1,0 -1,-1 0,-1 0,-1 2,0 1,0 1,0 1,0 -1,3 0,1 1,1 0,1 0,1 1,1 0,1 0,1 0,2 0,1 0,1 1,1 1,0 1,-1 1,0 1,-1 0,-1 1,0 1,-1 1,1 1,1 1,2 0,1 0,1 -1,1"
           id="path452"
           style="fill:#d40000;fill-opacity:1" />
      </g>

Somehow I have to search for the first value in the reference file - then change the fill property just before the </g> in each of the paragraphs. So I have to identify the correct style to change then iterate to the next row in the source file until end.

Can someone point me in the direction of commands to use please?

Moderator's Comments:
Mod Comment Code tags, please!

Last edited by radoulov; 10-11-2013 at 04:57 PM..
# 2  
Old 10-11-2013
Use Code tag and show output sample
# 3  
Old 10-11-2013
Sorry I don't understand what you mean? I don't know how to approach this and would like pointers.
# 4  
Old 10-11-2013
Quote:
Originally Posted by majikins
Sorry I don't understand what you mean? I don't know how to approach this and would like pointers.
You mean you want replace MP304, with d40000 ?

select your text and click code button for codetag
# 5  
Old 10-11-2013
Oh!

ok source file is

MP304,d40000
MP310,ff0000

File to work on:

Code:
<g
         transform="translate(-312.51946,80.94618)"
         id="MP302"
         style="fill:#ff0000;fill-opacity:1">
        <title
           id="title4028">Msukaligwa</title>
        <path
           d="m 1282,344 1,-1 1,0 1,0 3,0 1,0 1,0 1,0 1,1 1,1 -1,2 -1,0  1,0 0,1 1,0 0,1 1,1 0,1 -2,0 -2,0 0,1 -1,0 0,1 1,3 0,1 1,1 -1,1 -2,1  -1,0 -1,1 -1,-1 0,-1 -1,0 -1,-1 -1,0 -1,0 -1,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1 1,-1 2,1 1,1 0,-1 2,-1 1,-1 1,0 0,1 1,1 0,1 1,1 0,-1 1,-1 1,0  1,0 1,0 1,0 1,0 1,0 1,0 1,1 1,0 0,1 1,-1 1,0 0,-1 1,0 0,-1 2,0 0,-1 1,0  1,1 1,0 2,0 0,1 1,0 1,0 1,0 1,0 0,1 0,1 0,1 1,0 1,-1 1,-1 1,-2 0,1 1,0  1,0 1,-1 1,0 2,0 2,-1 1,-1 0,1 1,1 0,1 1,0 1,-1 -1,-1 1,-2 2,1 1,1 1,0  1,0 3,2 1,1 1,0 1,0 1,0 1,-1 1,0 1,0 1,0 1,-1 1,0 0,1 1,1 1,2 0,1 0,-1  0,1 0,-1 0,1 -1,2 0,2"
           id="path446"
           style="fill:#ff0000;fill-opacity:1" />
      </g>
      <g
         transform="translate(-312.51946,80.94618)"
         id="MP303"
         style="fill:#d40000;fill-opacity:1">
        <title
           id="title4034">Mkhondo </title>
        <path
           d="m 1279,409 -2,0 -1,0 -1,0 -1,0 -1,0 -1,1 -1,0 -1,1 -2,1  -1,0 -1,0 0,-1 0,1 -1,0 -1,0 -1,-1 -1,-1 -1,0 -1,0 1,-1 0,-1 -1,-1 -1,0  1,-1 1,-1 1,0 1,0 1,0 1,-1 0,-1 0,-2 1,0 -1,-1 1,-1 0,-1 0,-1 -1,-2  -1,-1 -1,-1 -1,1 -1,0 0,1 -1,1 -1,0 -1,1 -1,0 -1,-1 0,-1 0,-1 0,-2 0,-1  0,-1 -1,-1 0,-1 0,-1 -1,-1 0,-1 1,-3 2,0 2,0 1,0 1,-2 0,-1 0,-1 1,0 1,0  1,0 1,0 1,0 0,-1 0,1 0,-1 1,0 1,0 1,0 1,0 1,0 1,0 0,-1 -1,0 1,0 1,0 0,-1  1,0 1,0 1,0 0,-1 0,1 0,-1 1,0 0,-1 1,0 0,-1 -1,0 1,0 0,-1 0,-1 1,-1 1,0  1,0 1,0 0,-1 -1,0 -2,0 -1,0 -1,0 -1,-1 -1,0 0,-1 -1,0 0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id="path449"
           style="fill:#d40000;fill-opacity:1" />
      </g>
      <g
         transform="translate(-312.51946,80.94618)"
         id="MP304"
         style="fill:#d40000;fill-opacity:1">
        <title
           id="title4040">Pixley Ka Seme</title>
        <path
           d="m 1265,400 1,1 -1,0 0,2 0,1 -1,1 -1,0 -1,0 -1,0 -1,1 -1,1  1,0 1,1 0,1 -1,1 1,0 1,0 1,1 1,1 1,0 1,0 0,-1 0,1 1,0 1,0 2,-1 1,-1 1,0  1,-1 1,0 1,0 1,0 1,0 2,0 -1,1 -1,1 0,1 -1,2 -1,0 1,1 -2,2 1,1 1,0 0,1  0,1 -1,0 -1,0 0,-1 -1,0 0,1 -1,0 -1,0 0,1 0,-1 0,1 -1,0 0,-1 0,1 -1,0  0,-1 -1,0 0,-1 0,-1 0,-1 0,-1 -1,0 -1,0 0,1 0,-1 -1,0 -1,0 -1,0 1,0 0,1  0,1 -1,0 0,1 -1,0 -1,0 -1,-1 0,1 -1,0 0,1 -1,0 -1,0 0,1 0,1 0,1 0,1 -1,0  -1,0 -1,0 0,1 -1,0 0,-1 0,-1 -1,0 -1,0 -1,0 0,1 -1,0 0,1 -1,0 -1,0 0,1  0,1 -1,0 -1,-1 -1,0 0,-1 -1,0 0,-1 -1,0 -1,0 -1,0 0,1 -1,0 -1,0 -1,1  -1,0 0,-1 -1,0 -1,0 0,-1 -1,0 -1,0 0,-1 -1,0 -1,0 -1,0 0,1 -1,0 0,1 -1,0  0,-1 -1,0 0,1 -1,0 -1,0 -1,0 0,1 0,1 -1,0 0,1 -1,0 0,1 0,1 -1,0 0,1  -1,0 0,-1 -1,0 -1,0 0,-1 -1,0 -1,0 -1,0 -1,0 0,1 -1,0 1,0 -1,0 1,0 0,1  -1,0 1,0 -1,1 1,0 0,1 -1,0 -1,0 1,0 0,1 -1,0 -1,0 0,-1 0,1 0,-1 0,1 0,-1  0,1 0,-1 -1,0 0,1 -1,0 -1,0 -1,0 0,-1 -1,1 0,-1 0,-1 0,-1 -1,0 -1,0  0,-1 0,-1 -1,0 -1,0 0,-1 0,-1 0,-1 -1,0 0,-1 0,1 -1,0 0,-1 1,0 -1,0 0,-1  0,1 -1,0 0,-1 0,-1 -1,0 -1,0 0,-1 1,0 0,-1 -1,0 0,1 0,-1 -1,0 0,-1 0,-1  0,-1 -1,0 1,0 -1,0 0,-1 0,1 0,-1 -1,0 1,0 -1,0 0,-1 -1,0 0,-1 -1,0 1,-1  1,-1 1,0 3,-3 -1,-1 1,0 1,0 1,0 1,1 1,0 0,-1 1,-1 0,-1 0,-1 0,-1 1,-1  1,0 1,-1 1,0 1,0 0,-1 -1,-1 1,0 0,-1 1,-2 1,0 0,-1 0,-1 0,-1 0,-1 0,-1  0,-1 1,0 0,-1 0,-2 0,-1 0,-1 -1,-1 0,-1 1,0 1,0 1,0 0,-1 0,1 1,0 0,-1  1,0 0,-1 0,1 1,0 0,1 0,-1 1,0 0,-1 1,0 0,1 1,0 0,1 0,-1 1,0 1,0 0,-1  -1,0 0,-1 1,0 0,1 0,-1 1,0 -1,0 0,-1 1,0 0,1 1,0 0,1 1,0 0,-1 1,0 -1,0  0,-1 1,0 -1,0 1,0 -1,0 0,-1 1,0 0,1 1,0 1,0 -1,0 0,-1 1,0 -1,0 0,-1 1,0  0,1 1,0 0,-1 0,1 1,0 0,-1 0,1 1,0 0,-1 0,1 0,-1 1,0 0,-1 1,0 1,0 1,0  0,-1 1,-2 0,-1 1,-1 1,0 1,0 1,1 1,0 0,-1 1,0 0,1 2,0 2,2 1,-1 1,2 1,1  -2,1 0,2 1,0 0,1 0,1 1,0 1,0 1,2 1,0 1,0 -1,-1 0,-1 0,-1 2,0 1,0 1,0 1,0  -1,3 0,1 1,1 0,1 0,1 1,1 0,1 0,1 0,2 0,1 0,1 1,1 1,0 1,-1 1,0 1,-1 0,-1  1,0 1,-1 1,1 1,1 1,2 0,1 0,1 -1,1"
           id="path452"
           style="fill:#d40000;fill-opacity:1" />
      </g>

So I have to find the value MP304 - then in the "paragraph" where MP304 is ie between the <g and /g>, change the style value of that code tag to what the source file says for that MP304 value. Then I have to iterate - go to next line in source file and search for MP305, and do the same for its value.

Sorry I am new to how to use this - Thank you for your responses.

Last edited by radoulov; 10-11-2013 at 05:00 PM..
# 6  
Old 10-11-2013
try

Code:
$ cat file1
MP304,d40000
MP310,ff0000

Code:
$ cat file2
id="path449"
style="fill:#d40000;fill-opacity:1" />
</g>
<g
transform="translate(-312.51946,80.94618)"
id="MP304"
style="fill:#d40;fill-opacity:1">
<title
id="title4040">Pixley Ka Seme</title>
<path
d="m 1265,400 1,1 -1,0 0,2 0,1 -1,1 -1,0 -1,0 -1,0 -1,1 -1,1 1,0 1,1 0,1 -1,1 1,0 1,0 1,1 1,1 1,0 1,0 0,-1 0,1 1,0 1,0 2,-1 1,-1 1,0 1,-1 1,0 1,0 1,0 1,0 2,0 -1,1 -1,1 0,1 -1,2 -1,0 1,1 -2,2 1,1 1,0 0,1 0,1 -1,0 -1,0 0,-1 -1,0 0,1 -1,0 -1,0 0,1 0,-1 0,1 -1,0 0,-1 0,1 -1,0 0,-1 -1,0 0,-1 0,-1 0,-1 0,-1 -1,0 -1,0 0,1 0,-1 -1,0 -1,0 -1,0 1,0 0,1 0,1 -1,0 0,1 -1,0 -1,0 -1,-1 0,1 -1,0 0,1 -1,0 -1,0 0,1 0,1 0,1 0,1 -1,0 -1,0 -1,0 0,1 -1,0 0,-1 0,-1 -1,0 -1,0 -1,0 0,1 -1,0 0,1 -1,0 -1,0 0,1 0,1 -1,0 -1,-1 -1,0 0,-1 -1,0 0,-1 -1,0 -1,0 -1,0 0,1 -1,0 -1,0 -1,1 -1,0 0,-1 -1,0 -1,0 0,-1 -1,0 -1,0 0,-1 -1,0 -1,0 -1,0 0,1 -1,0 0,1 -1,0 0,-1 -1,0 0,1 -1,0 -1,0 -1,0 0,1 0,1 -1,0 0,1 -1,0 0,1 0,1 -1,0 0,1 -1,0 0,-1 -1,0 -1,0 0,-1 -1,0 -1,0 -1,0 -1,0 0,1 -1,0 1,0 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,1 1,1 0,1 0,1 0,2 0,1 0,1 1,1 1,0 1,-1 1,0 1,-1 0,-1 1,0 1,-1 1,1 1,1 1,2 0,1 0,1 -1,1"
id="path452"
style="fill:#d40abc;fill-opacity:1" />
</g>

Code:
$ awk -F, 'FNR==NR{A["\""$1"\""]=$2;next}{for(i in A)if($0~i)R=A[i];if(R && $0~/style/){j++;if(j==2){gsub(/#.*;/,"#"R";");R=j=""}}}1'  file1 file2

Resulting

Code:
id="path449"
style="fill:#d40000;fill-opacity:1" />
</g>
<g
transform="translate(-312.51946,80.94618)"
id="MP304"
style="fill:#d40;fill-opacity:1">
<title
id="title4040">Pixley Ka Seme</title>
<path
d="m 1265,400 1,1 -1,0 0,2 0,1 -1,1 -1,0 -1,0 -1,0 -1,1 -1,1 1,0 1,1 0,1 -1,1 1,0 1,0 1,1 1,1 1,0 1,0 0,-1 0,1 1,0 1,0 2,-1 1,-1 1,0 1,-1 1,0 1,0 1,0 1,0 2,0 -1,1 -1,1 0,1 -1,2 -1,0 1,1 -2,2 1,1 1,0 0,1 0,1 -1,0 -1,0 0,-1 -1,0 0,1 -1,0 -1,0 0,1 0,-1 0,1 -1,0 0,-1 0,1 -1,0 0,-1 -1,0 0,-1 0,-1 0,-1 0,-1 -1,0 -1,0 0,1 0,-1 -1,0 -1,0 -1,0 1,0 0,1 0,1 -1,0 0,1 -1,0 -1,0 -1,-1 0,1 -1,0 0,1 -1,0 -1,0 0,1 0,1 0,1 0,1 -1,0 -1,0 -1,0 0,1 -1,0 0,-1 0,-1 -1,0 -1,0 -1,0 0,1 -1,0 0,1 -1,0 -1,0 0,1 0,1 -1,0 -1,-1 -1,0 0,-1 -1,0 0,-1 -1,0 -1,0 -1,0 0,1 -1,0 -1,0 -1,1 -1,0 0,-1 -1,0 -1,0 0,-1 -1,0 -1,0 0,-1 -1,0 -1,0 -1,0 0,1 -1,0 0,1 -1,0 0,-1 -1,0 0,1 -1,0 -1,0 -1,0 0,1 0,1 -1,0 0,1 -1,0 0,1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1 1,0 1,0 1,2 1,0 1,0 -1,-1 0,-1 0,-1 2,0 1,0 1,0 1,0 -1,3 0,1 1,1 0,1 0,1 1,1 0,1 0,1 0,2 0,1 0,1 1,1 1,0 1,-1 1,0 1,-1 0,-1 1,0 1,-1 1,1 1,1 1,2 0,1 0,1 -1,1"
id="path452"
style="fill:#d40000;fill-opacity:1" />
</g>


Last edited by Akshay Hegde; 10-11-2013 at 03:24 PM..
# 7  
Old 10-11-2013
Will try now however I see that you highlighted the style line just after id="MP304" - this is not the line I am interested in but the one before the </g> This is what is frustrating me on how to get to it ie below:

Code:
<g
         transform="translate(-312.51946,80.94618)"
         id=" MP304 "        style="fill:#d40000;fill-opacity:1"><title
           id="title4040">Pixley Ka Seme</title>
        <path
           d="m 1265,400 1,1 -1,0 0,2 0,1 -1,1 -1,0 -1,0 -1,0 -1,1 -1,1   1,0 1,1 0,1 -1,1 1,0 1,0 1,1 1,1 1,0 1,0 0,-1 0,1 1,0 1,0 2,-1 1,-1 1,0   1,-1 1,0 1,0 1,0 1,0 2,0 -1,1 -1,1 0,1 -1,2 -1,0 1,1 -2,2 1,1 1,0 0,1   0,1 -1,0 -1,0 0,-1 -1,0 0,1 -1,0 -1,0 0,1 0,-1 0,1 -1,0 0,-1 0,1 -1,0   0,-1 -1,0 0,-1 0,-1 0,-1 0,-1 -1,0 -1,0 0,1 0,-1 -1,0 -1,0 -1,0 1,0 0,1   0,1 -1,0 0,1 -1,0 -1,0 -1,-1 0,1 -1,0 0,1 -1,0 -1,0 0,1 0,1 0,1 0,1  -1,0  -1,0 -1,0 0,1 -1,0 0,-1 0,-1 -1,0 -1,0 -1,0 0,1 -1,0 0,1 -1,0 -1,0  0,1  0,1 -1,0 -1,-1 -1,0 0,-1 -1,0 0,-1 -1,0 -1,0 -1,0 0,1 -1,0 -1,0  -1,1  -1,0 0,-1 -1,0 -1,0 0,-1 -1,0 -1,0 0,-1 -1,0 -1,0 -1,0 0,1 -1,0  0,1 -1,0  0,-1 -1,0 0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,1 2,0 2,2  1,-1 1,2 1,1  -2,1 0,2 1,0 0,1 0,1 1,0 1,0 1,2 1,0 1,0 -1,-1 0,-1 0,-1  2,0 1,0 1,0 1,0  -1,3 0,1 1,1 0,1 0,1 1,1 0,1 0,1 0,2 0,1 0,1 1,1 1,0  1,-1 1,0 1,-1 0,-1  1,0 1,-1 1,1 1,1 1,2 0,1 0,1 -1,1"
           id="path452"
           style="fill:# d40000 ;fill-opacity:1" />      </g>

---------- Post updated at 08:10 PM ---------- Previous update was at 07:49 PM ----------

Works great as you showed above! Thank you! Now just got to figure out not to change the next line with style but the next one.

Last edited by radoulov; 10-11-2013 at 04:58 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Taking key values from one file and extracting values from another file

Hi, I have two files with values in both. File1: cat 2 3 dog 4 5 elephant 6 7 camel 2 3 File2: ----+--gkf;ajf= ---+---- +----- cat -------=----+ 3 | 4 ----- dog ------++-- 5 | 9 ----++-- elephant | 5 | 7 ---++ camel ------ ++++_---- || 8 | 9 I want the final file as: cat 4... (1 Reply)
Discussion started by: npatwardhan
1 Replies

2. Shell Programming and Scripting

Replace values on file

Gents, Please i need your help. Using the file2.txt i will like to replace values in file3.txt. Example in file 2 column 1 is the value to find in file3.txt and replace with value in colunm2 (file2.txt). Example file2.txt 21 1209 22 1210file3.txt SCI TB Timestamp Local : 8/30/17... (2 Replies)
Discussion started by: jiam912
2 Replies

3. UNIX for Dummies Questions & Answers

awk to replace values in one file using a second reference file

Hi, I'd be grateful for your help with the following: I have a file with a single column (file1). Let's say the values are: a b c 5 d I have a second, reference file (ref_file), which is colon-delimited, and is effectively a key. Let's say the values in it are: a:1 b:2 c:3 d:4... (4 Replies)
Discussion started by: aberg
4 Replies

4. Shell Programming and Scripting

Replace values using other file

Gents, Please can you help me. I need to update file1 using file2 values file1 S 44519.00 49349.00 1V1 0.0 0 0.0 0.0 0.0 0.0289091513 S 44513.00 48581.00 1V1 0.0 0 0.0 0.0 0.0 0.0289094319 S 44511.00 48605.00 1V1 0.0 0 0.0... (1 Reply)
Discussion started by: jiam912
1 Replies

5. Shell Programming and Scripting

Replace column values from other file

I have one file as it has the following format File1 S No Site IP Address 1 Australia 192.168.0.1/26 2 Australia 192.168.0.2/26 3 Australia 192.168.0.3/26 I need awk/sed command to replace the column2 value ( under Site) with some other... (8 Replies)
Discussion started by: samaritan
8 Replies

6. Shell Programming and Scripting

Replace values in a file with values from another file

Hi, I have 2 input files: File 1: echo Name > create_Name.txt echo Group /dir/group, Name >> create_Name.txt File 2: Name AAA BBB CCC group A B C dir A1 B1 C1 ................................ Need to replace the contents of File 1 with column 2, 3 & 4 values of File 2... (8 Replies)
Discussion started by: gctex
8 Replies

7. Shell Programming and Scripting

Compare values in two files. For matching rows print corresponding values from File 1 in File2.

- I have two files (File 1 and File 2) and the contents of the files are mentioned below. - I am trying to compare the values of Column1 of File1 with Column1 of File2. If a match is found, print the corresponding value from Column2 of File1 in Column5 of File2. - I tried to modify and use... (10 Replies)
Discussion started by: Santoshbn
10 Replies

8. UNIX for Dummies Questions & Answers

replace a column with values from another file

Dear all, I have a file1.pdb in pdb format and a dat file2 containing values, corresponding to the atoms in the pdb file. these values (file2.dat) need to be in the column instead of the 0.00 (file1) values for each atom in file1.pdb .(the red values must be replaced by the blue ones,in order)... (11 Replies)
Discussion started by: chen.xiao.po
11 Replies

9. UNIX for Dummies Questions & Answers

Replace values in a specified column of a file

Hello, I have a file with four columns and I would like to replace values in the second column only. An arbitrary example is: 100 A 105 B 200 B 205 C 300 C 305 D 400 D 405 E 500 E 505 F I need to replace the second column as shown below: ... (4 Replies)
Discussion started by: Gussifinknottle
4 Replies

10. UNIX for Dummies Questions & Answers

Find and Replace based on values in an file

I have a file in which I want to do multiple find and replace of strings. For a single replace I can implement: sed -i 's/old/new/' <input_file> I have a second file that contains the old and the new values like the arbitrary example below: old new xyz pqr ab 756 rst pqr... (3 Replies)
Discussion started by: Gussifinknottle
3 Replies
Login or Register to Ask a Question