<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Replace string in a file in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/Replace-string-in-a-file/m-p/2264576#M44368</link>
    <description>After your tJavaRow you have to write line by line into a new file, backup to old one and rename the new into the old file name.</description>
    <pubDate>Thu, 23 Jan 2014 20:06:25 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2014-01-23T20:06:25Z</dc:date>
    <item>
      <title>Replace string in a file</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Replace-string-in-a-file/m-p/2264574#M44366</link>
      <description>Hi All, 
&lt;BR /&gt;I have a problem with Talend, I cannot find any answer to my problem. 
&lt;BR /&gt;I have a directory with various xml files inside, each xml is different (not the same structure) 
&lt;BR /&gt;I have to replace one of the first line of each xml file, in the first tag there is a key name (always the same name) and I have to change the value. 
&lt;BR /&gt;example : &amp;lt;my tag myKey="blablabla" &amp;gt; 
&lt;BR /&gt;and replace it like : &amp;lt;my tag myKey="anotherblablabla" &amp;gt; 
&lt;BR /&gt;So I start my job like this : 
&lt;BR /&gt;tFileList-&amp;gt;tFileInputFullRow-&amp;gt;tJavaRow-&amp;gt; ???? 
&lt;BR /&gt;So tFileList is listing my files, no problem, 
&lt;BR /&gt;I user tFileInputFullRow because the tFileInputXml want my to describe my xml schema, or each file can a a different schema. 
&lt;BR /&gt;So in tJavaRow, I read the current row, if I find myKey, I can replace the content, that's ok. 
&lt;BR /&gt;But now, how I can replace the line in the file ? How I can tell, replace current line in the file ? 
&lt;BR /&gt;I don't want to create a new file with each iteration (by rewriting line by line) because it will spend a lot of time for just one change. 
&lt;BR /&gt;Hope that someone can help me 
&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009MACn.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/154443iC5B8CACEF3D12C6A/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009MACn.png" alt="0683p000009MACn.png" /&gt;&lt;/span&gt; 
&lt;BR /&gt;Thanks !</description>
      <pubDate>Thu, 23 Jan 2014 10:04:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Replace-string-in-a-file/m-p/2264574#M44366</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-01-23T10:04:53Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string in a file</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Replace-string-in-a-file/m-p/2264575#M44367</link>
      <description>You should be able to do this using a shell script (on Linux/UNIX) or batch program (Windows). Assuming it's Linux, you could use the sed utility to find and replace instances of they key in the files, without caring about their structures. 
&lt;BR /&gt; 
&lt;BR /&gt;Using sed, the following code replaces all occurences of Mary Sanders to Mary Jones in the file customer.txt: 
&lt;BR /&gt; 
&lt;BR /&gt;cat customer.txt | \ 
&lt;BR /&gt;sed -e 's/Mary Sanders/Mary Jones/' &amp;gt; customer.txt 
&lt;BR /&gt; 
&lt;BR /&gt;So in your case, it would be: 
&lt;BR /&gt; 
&lt;BR /&gt;"/bin/sh " + 
&lt;BR /&gt;" cat " + ((String)globalMap.get("tFileList_1_CURRENT_FILEPATH")) + " | \" + 
&lt;BR /&gt;" sed -e 's/blablabla/anotherblablabla/' &amp;gt; " + ((String)globalMap.get("tFileList_1_CURRENT_FILEPATH")) 
&lt;BR /&gt;I've not tested this end to end - but should work based on similar stuff I've done... 
&lt;BR /&gt; 
&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009MCWg.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/149046i0DD0983751382D81/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009MCWg.png" alt="0683p000009MCWg.png" /&gt;&lt;/span&gt;</description>
      <pubDate>Thu, 23 Jan 2014 16:25:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Replace-string-in-a-file/m-p/2264575#M44367</guid>
      <dc:creator>willm1</dc:creator>
      <dc:date>2014-01-23T16:25:37Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string in a file</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Replace-string-in-a-file/m-p/2264576#M44368</link>
      <description>After your tJavaRow you have to write line by line into a new file, backup to old one and rename the new into the old file name.</description>
      <pubDate>Thu, 23 Jan 2014 20:06:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Replace-string-in-a-file/m-p/2264576#M44368</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-01-23T20:06:25Z</dc:date>
    </item>
  </channel>
</rss>

