jadda Absent Member.
Absent Member.
804 views

How to Modify Contents of Text file

Jump to solution

 

I  have a text file in my server.I want to modify contents of text file.I am able to overwrite contents of text file and Append to current file.But i can't replace particular word from  text file.I want to search a word from text file and i want to replace it

 

  Please help me on this.

Labels (1)
0 Likes
1 Solution

Accepted Solutions
Absent Member.. Steve_Drummond Absent Member..
Absent Member..

Re: How to Modify Contents of Text file

Jump to solution

Hi,

 

You can use the operation /lib/filesystem/.../read file to read the contents of the file into a variable. You can then use /lib/utility operations/search and replace to change the text.

 

If you then wish to write back to the file you would use /lib/filesystem/.../write to file to overwrite the original file.

 

Hope that helps.

 

-steve

0 Likes
3 Replies
Absent Member.. Steve_Drummond Absent Member..
Absent Member..

Re: How to Modify Contents of Text file

Jump to solution

Hi,

 

You can use the operation /lib/filesystem/.../read file to read the contents of the file into a variable. You can then use /lib/utility operations/search and replace to change the text.

 

If you then wish to write back to the file you would use /lib/filesystem/.../write to file to overwrite the original file.

 

Hope that helps.

 

-steve

0 Likes
jadda Absent Member.
Absent Member.

Re: How to Modify Contents of Text file

Jump to solution

Steve,

  Thanks for your response.The procedure you have suggested is very long process.More over the content i wish modify is very crucial or criticali can't perform so many operations on that.

 

Do we have any operation like  'Write to file'  to modify contents

0 Likes
Absent Member.. Steve_Drummond Absent Member..
Absent Member..

Re: How to Modify Contents of Text file

Jump to solution

Very long process? It's 3 steps.

 

You could use "Append to File" to write contents to the end of the existing file. However, if you want to modify text within the file (say change hostname from one to another) there is no alternative to reading the file, replacing text and then re-writing the file. This is not just HPOO, you would need to do the same process in a programming language.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.