tag:blogger.com,1999:blog-106449775438946661.post5802458176711634714..comments2024-03-19T05:14:38.879-07:00Comments on Overcoming Fear: Unix Command to Find And Replace Text in a FileTim Myerhttp://www.blogger.com/profile/01514263555690798238noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-106449775438946661.post-24773172937586527982012-08-29T11:03:25.053-07:002012-08-29T11:03:25.053-07:00Sure Tim, I'll give a try.
Thanks for your ti...Sure Tim, I'll give a try.<br /><br />Thanks for your time and efforts.<br />I really appreciate.<br /><br />This is a very good blog.<br />-- Keep Going..!!Srihttps://www.blogger.com/profile/07434362175666267599noreply@blogger.comtag:blogger.com,1999:blog-106449775438946661.post-4986266953889210262012-08-29T11:00:04.101-07:002012-08-29T11:00:04.101-07:00Hi Sri,
Why not try it out with the test case you ...Hi Sri,<br />Why not try it out with the test case you gave me in order to answer your own question ;)<br />Best,<br />---Tim---Tim Myerhttps://www.blogger.com/profile/01514263555690798238noreply@blogger.comtag:blogger.com,1999:blog-106449775438946661.post-38683140605184025312012-08-29T10:57:21.247-07:002012-08-29T10:57:21.247-07:00Yeah, Tim.
I hope, this solves my problem.
Just ...Yeah, Tim.<br /><br />I hope, this solves my problem.<br /><br />Just a small clarification; This will add the text from A to B or from B to A..??<br />Question might be silly, forgive my ignorance.Srihttps://www.blogger.com/profile/07434362175666267599noreply@blogger.comtag:blogger.com,1999:blog-106449775438946661.post-84094673105102404552012-08-29T10:51:01.102-07:002012-08-29T10:51:01.102-07:00Hi Sri,
Thanks for clarifying. Perhaps this will ...Hi Sri,<br /><br />Thanks for clarifying. Perhaps this will help:<br /> <i>B_CONTENTS=`cat B.txt` perl -pi -e 's~3~3 $ENV{B_CONTENTS}~' A.txt</i>Tim Myerhttps://www.blogger.com/profile/01514263555690798238noreply@blogger.comtag:blogger.com,1999:blog-106449775438946661.post-384679083200847582012-08-29T10:32:44.573-07:002012-08-29T10:32:44.573-07:00Thanks, Tim.
Am not exactly looking for concatenat...Thanks, Tim.<br />Am not exactly looking for concatenating.<br /><br />Simply, find a text in one file and add the text from another file.<br />Eg:<br />A.txt<br />Contents: 1 2 3 4 5 6<br />B.txt<br />Contents: 7 8 9 10 11 12<br /><br />Search A for '3' and add the contents from B.<br />Final output: 1 2 3 7 8 9 10 11 12 4 5 6<br /><br />Srihttps://www.blogger.com/profile/07434362175666267599noreply@blogger.comtag:blogger.com,1999:blog-106449775438946661.post-37978389462794688042012-08-29T09:44:56.717-07:002012-08-29T09:44:56.717-07:00Hi Sri,
If you are just looking to concatenate the...Hi Sri,<br />If you are just looking to concatenate the contents of one file onto another perhaps you could just use 'cat'.<br /><br />For example, would 'cat A.txt B.txt > A.txt' be sufficient?<br /><br />If you do not want line separators, then you could also use 'cat A.txt B.txt | tr -d '\n' > A.txt'<br /><br />I hope that helps,<br />---Tim---Tim Myerhttps://www.blogger.com/profile/01514263555690798238noreply@blogger.comtag:blogger.com,1999:blog-106449775438946661.post-66700324932072774952012-08-29T05:42:03.990-07:002012-08-29T05:42:03.990-07:00Hey, its a very nice blog.
I've a scenario but...Hey, its a very nice blog.<br />I've a scenario but am not sure how to solve this.<br />I've two files; <br />A.txt (contents aaa)<br />and B.txt (contents bbb)<br />I need to find the string 'aaa' from A.txt and after finding, I've to add string 'bbb' from B.txt<br />Finally, contents of A.txt should be 'aaabbb'<br />Any help would be much appreciatedSrihttps://www.blogger.com/profile/07434362175666267599noreply@blogger.comtag:blogger.com,1999:blog-106449775438946661.post-41337070293010057562012-01-11T02:38:51.952-08:002012-01-11T02:38:51.952-08:00nice command . I used it first timenice command . I used it first timepavanhttps://www.blogger.com/profile/04413357064133085498noreply@blogger.comtag:blogger.com,1999:blog-106449775438946661.post-5586468385079850212011-10-18T14:09:14.925-07:002011-10-18T14:09:14.925-07:00Hi Mangal,
I am not sure why I was not alerted to...Hi Mangal,<br /><br />I am not sure why I was not alerted to this comment, but hopefully this reply will be of use to someone else.<br />My inclination would be to do two find and replace operations: the first using the super-string and the second using the sub-string (which will no longer be a sub-string after the first replacement operation).<br /><br />Cheers,<br />---Tim---Tim Myerhttps://www.blogger.com/profile/01514263555690798238noreply@blogger.comtag:blogger.com,1999:blog-106449775438946661.post-92067590662753574052011-05-09T09:12:27.707-07:002011-05-09T09:12:27.707-07:00Tim,
I need to find following words "ABC...Tim,<br /> I need to find following words "ABC Category Code Description" and "ABC Category Code" and replace it with "XYZ Category Code Description" and "XYZ Category Code" respectively. How your script to be modified? My dilemma is that one string to be replaced is subset of the another. Any help will be greatly appreciated.Mangalhttps://www.blogger.com/profile/07040431010123362644noreply@blogger.comtag:blogger.com,1999:blog-106449775438946661.post-11103323892357361702009-05-29T19:34:41.200-07:002009-05-29T19:34:41.200-07:00This was so useful. ThanksThis was so useful. ThanksSP Balamuruganhttps://www.blogger.com/profile/12326239145933921002noreply@blogger.comtag:blogger.com,1999:blog-106449775438946661.post-60185030768774062002008-10-14T13:46:00.000-07:002008-10-14T13:46:00.000-07:00Nice, it helped me avoid monotony and save time.Nice, it helped me avoid monotony and save time.Sampath Peechuhttps://www.blogger.com/profile/15806807861060375170noreply@blogger.comtag:blogger.com,1999:blog-106449775438946661.post-53102937460874983562008-05-12T08:03:00.000-07:002008-05-12T08:03:00.000-07:00I appreciate the feedback and am happy to be of he...I appreciate the feedback and am happy to be of help.Tim Myerhttps://www.blogger.com/profile/01514263555690798238noreply@blogger.comtag:blogger.com,1999:blog-106449775438946661.post-26879014136681982872008-05-11T21:13:00.000-07:002008-05-11T21:13:00.000-07:00It came up as my first google and I used it to pre...It came up as my first google and I used it to prepare my deep sequencing files for downstream analysis.<BR/>Thank you very much for your help.<BR/>Joseph Dhahbi<BR/>CHORI Oakland CAUnknownhttps://www.blogger.com/profile/06252871610936040938noreply@blogger.com