{"id":2780,"date":"2023-04-25T15:06:27","date_gmt":"2023-04-25T06:06:27","guid":{"rendered":"https:\/\/derrylab.com\/?p=2780"},"modified":"2023-04-25T22:50:18","modified_gmt":"2023-04-25T13:50:18","slug":"how-to-replace-string-in-files-without-text-editor-in-linux","status":"publish","type":"post","link":"https:\/\/blog.derrylab.com\/index.php\/2023\/04\/25\/how-to-replace-string-in-files-without-text-editor-in-linux\/","title":{"rendered":"How to Replace String in Files without Text Editor in Linux"},"content":{"rendered":"\n<p>As a Linux user, it&#8217;s important to know how to modify text files through the command line. One common scenario is changing a single line in a text file, such as enabling or disabling a feature. But what if the OS doesn&#8217;t have any text editor installed at all?<\/p>\n\n\n\n<p>In this tutorial, we&#8217;ll cover how to find and replace a line in a text file without using a text editor, and we&#8217;ll use the example of enabling <code>allow_url_include<\/code> in the <code>php.ini<\/code> configuration file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Locate the Text File<\/h2>\n\n\n\n<p>The first step is to locate the text file that you want to modify. In this example, we&#8217;ll use the <code>php.ini<\/code> which is a text file located in the <code>\/etc\/php\/7.0\/cli<\/code> directory.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Check the Current Value<\/h2>\n\n\n\n<p>Before making any changes, it&#8217;s important to check the current value of the setting that you want to modify. In this example, we want to enable <code>allow_url_include<\/code>, which should be set to <code>Off<\/code> by default. To check the current value, we can use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep \"allow_url_include\" \/etc\/php\/7.0\/cli\/php.ini\n<\/code><\/pre>\n\n\n\n<p>This should output a line that shows the current value of <code>allow_url_include<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Modify the Configuration File<\/h2>\n\n\n\n<p>To modify the configuration file, we can use the <code>sed<\/code> command. The <code>sed<\/code> command is a powerful stream editor that can perform text transformations on an input stream (a file or input from a pipe). In this example, we&#8217;ll use <code>sed<\/code> to replace <code>allow_url_include = Off<\/code> with <code>allow_url_include = On<\/code>.<\/p>\n\n\n\n<p>Here&#8217;s the command to make the change (since my file is in root directory then I need <code>sudo<\/code> ):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo sed -i 's\/allow_url_include = Off\/allow_url_include = On\/g' \/etc\/php\/7.0\/cli\/php.ini\n<\/code><\/pre>\n\n\n\n<p>This command will search for the string <code>allow_url_include = Off<\/code> and replace it with <code>allow_url_include = On<\/code> in the <code>php.ini<\/code> file.<\/p>\n\n\n\n<p>The <code>-i<\/code> option tells <code>sed<\/code> to modify the file in place, and the <code>g<\/code> at the end of the command tells <code>sed<\/code> to replace all occurrences of the string, not just the first one.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Verify the Change<\/h2>\n\n\n\n<p>To verify that the change was made successfully, we can run the same <code>grep<\/code> command previously:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep \"allow_url_include\" \/etc\/php\/7.0\/cli\/php.ini\n<\/code><\/pre>\n\n\n\n<p>This should output a line that shows the new value of <code>allow_url_include<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>In this tutorial, we learned how to modify a configuration file in Linux without using a text editor. We used the <code>sed<\/code> command to find and replace a line in the <code>php.ini<\/code> configuration file, but you can use this technique to modify any configuration file on your system. You should always back up any files that you modify. \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As a Linux user, it&#8217;s important to know how to modify text files through the command line. One common scenario is changing a single line in a text file, such as enabling or disabling a feature. But what if the OS doesn&#8217;t have any text editor installed at all? In this tutorial, we&#8217;ll cover how [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2807,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4,5],"tags":[209,36,207,208,205,206],"class_list":["post-2780","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-programming","tag-baremetal","tag-linux","tag-sed","tag-string-replace","tag-text-editor","tag-text-replacement"],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2023\/04\/pexels-photo-1237647.jpeg?fit=1880%2C1253&ssl=1","jetpack-related-posts":[{"id":1282,"url":"https:\/\/blog.derrylab.com\/index.php\/2022\/08\/01\/problem-when-building-old-openssl-version-on-the-new-system\/","url_meta":{"origin":2780,"position":0},"title":"Problem When Building Old OpenSSL Version on The New System","author":"derry","date":"August 1, 2022","format":false,"excerpt":"The old OpenSSL seems to have a problem when built using a newer system. I got this problem when compiling OpenSSL 1.1.0f on my Ubuntu 22.04. derry@G14:~\/openssl-1.1.0f$ .\/config -d shared no-asm no-hw Operating system: x86_64-whatever-linux2 \"glob\" is not exported by the File::Glob module Can't continue after import errors at .\/Configure\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/blog.derrylab.com\/index.php\/category\/programming\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/08\/pexels-anamul-rezwan-1145434-scaled.jpg?fit=1200%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/08\/pexels-anamul-rezwan-1145434-scaled.jpg?fit=1200%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/08\/pexels-anamul-rezwan-1145434-scaled.jpg?fit=1200%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/08\/pexels-anamul-rezwan-1145434-scaled.jpg?fit=1200%2C800&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/08\/pexels-anamul-rezwan-1145434-scaled.jpg?fit=1200%2C800&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":962,"url":"https:\/\/blog.derrylab.com\/index.php\/2022\/05\/31\/how-to-access-som9331-serial-console-in-linux\/","url_meta":{"origin":2780,"position":1},"title":"How to Access SOM9331 Serial Console in Linux","author":"derry","date":"May 31, 2022","format":false,"excerpt":"I got this old hackable mini router board. It comes with OpenWRT but I can't seem to connect this via USB Serial. It turns out that the driver is not installed. Installation is quick but there is a minor change needed in order to build the driver on a recent\u2026","rel":"","context":"In &quot;linux&quot;","block_context":{"text":"linux","link":"https:\/\/blog.derrylab.com\/index.php\/category\/linux\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/05\/81IfBiOdCvL._AC_SL1500_.jpg?fit=1200%2C982&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/05\/81IfBiOdCvL._AC_SL1500_.jpg?fit=1200%2C982&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/05\/81IfBiOdCvL._AC_SL1500_.jpg?fit=1200%2C982&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/05\/81IfBiOdCvL._AC_SL1500_.jpg?fit=1200%2C982&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/05\/81IfBiOdCvL._AC_SL1500_.jpg?fit=1200%2C982&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":113,"url":"https:\/\/blog.derrylab.com\/index.php\/2020\/10\/22\/how-to-view-dot-files-in-ubuntu\/","url_meta":{"origin":2780,"position":2},"title":"How to View .dot Files in Ubuntu","author":"derry","date":"October 22, 2020","format":false,"excerpt":"I was working with LLVM recently to create a callgraph using opt -view-cfg. But unfortunately it doesn't work. Here is what I got instead: ibndias@SHAHEEN-XPS15:~\/Documents\/Projects$ opt -view-cfg file.bcWARNING: You're attempting to print out a bitcode file.This is inadvisable as it may cause display problems. Ifyou REALLY want to taste LLVM\u2026","rel":"","context":"In &quot;linux&quot;","block_context":{"text":"linux","link":"https:\/\/blog.derrylab.com\/index.php\/category\/linux\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2242,"url":"https:\/\/blog.derrylab.com\/index.php\/2022\/10\/18\/how-to-do-buffer-overflow-attack-on-64bit-machine\/","url_meta":{"origin":2780,"position":3},"title":"How to Do Buffer Overflow Attack on 64bit Machine","author":"derry","date":"October 18, 2022","format":false,"excerpt":"Professor's course material was out of date. He made an example of a buffer overflow attack several years ago. Then here I am, asked to fix the code to work on a modern machine, 64bit Kali Linux. There should be no difference with other Linux; you can practice this on\u2026","rel":"","context":"In &quot;linux&quot;","block_context":{"text":"linux","link":"https:\/\/blog.derrylab.com\/index.php\/category\/linux\/"},"img":{"alt_text":"giant tsunami wave","src":"https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/10\/pexels-photo-9156792.jpeg?fit=1200%2C737&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/10\/pexels-photo-9156792.jpeg?fit=1200%2C737&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/10\/pexels-photo-9156792.jpeg?fit=1200%2C737&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/10\/pexels-photo-9156792.jpeg?fit=1200%2C737&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/10\/pexels-photo-9156792.jpeg?fit=1200%2C737&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":92,"url":"https:\/\/blog.derrylab.com\/index.php\/2020\/07\/18\/how-to-create-identical-image-of-usb-device\/","url_meta":{"origin":2780,"position":4},"title":"How to Create Identical Image of USB Device","author":"derry","date":"July 18, 2020","format":false,"excerpt":"Hi, currently I am backing up my micro SD card contents and I'm using dd for that. You can start listing your usb device using: $ sudo fdisk -l After you get the USB address, for example mine is \/dev\/sdb, you can start creating a copy images. Here I tried\u2026","rel":"","context":"In &quot;linux&quot;","block_context":{"text":"linux","link":"https:\/\/blog.derrylab.com\/index.php\/category\/linux\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":120,"url":"https:\/\/blog.derrylab.com\/index.php\/2020\/11\/04\/install-xilinx-in-batch-mode\/","url_meta":{"origin":2780,"position":5},"title":"How to Install Xilinx using Command Line in Four Steps","author":"derry","date":"November 4, 2020","format":false,"excerpt":"I just got some problem with Xilinx 2020.1 installation on my Pop OS. The installer was stuck and gives me an error message: ibndias@shaheen:~\/Downloads$ .\/Xilinx_Unified_2020.1_0602_1208_Lin64.bin Verifying archive integrity... All good. Uncompressing Xilinx Installer............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... Exception in thread \"SPLASH_LOAD_MESSAGE\" java.lang.IllegalStateException: no splash screen available at java.desktop\/java.awt.SplashScreen.checkVisible(Unknown Source) at java.desktop\/java.awt.SplashScreen.getBounds(Unknown Source) at java.desktop\/java.awt.SplashScreen.getSize(Unknown\u2026","rel":"","context":"In &quot;linux&quot;","block_context":{"text":"linux","link":"https:\/\/blog.derrylab.com\/index.php\/category\/linux\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/posts\/2780","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/comments?post=2780"}],"version-history":[{"count":7,"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/posts\/2780\/revisions"}],"predecessor-version":[{"id":2811,"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/posts\/2780\/revisions\/2811"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/media\/2807"}],"wp:attachment":[{"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/media?parent=2780"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/categories?post=2780"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/tags?post=2780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}