
- Kali Linux Tutorial
- Kali Linux - Home
- Installation & Configuration
- Information Gathering Tools
- Vulnerability Analyses Tools
- Kali Linux - Wireless Attacks
- Website Penetration Testing
- Kali Linux - Exploitation Tools
- Kali Linux - Forensics Tools
- Kali Linux - Social Engineering
- Kali Linux - Stressing Tools
- Kali Linux - Sniffing & Spoofing
- Kali Linux - Password Cracking Tools
- Kali Linux - Maintaining Access
- Kali Linux - Reverse Engineering
- Kali Linux - Reporting Tools
- Kali Linux Useful Resources
- Kali Linux - Quick Guide
- Kali Linux - Useful Resources
- Kali Linux - Discussion
What is the sed in-place flag that works both on Mac and Linux?
We know that the SED command in Linux stands for stream editor and is mainly used to perform functions on files, and the functions usually are either searching for a word, or replacing it or insertion of something and few more. It is a very useful command and can be found on the Linux kernel.
It should also be noted that the BSD (Berkeley Software Distribution) sed shipped with the OS X does need the -i flag to work and the GNU one doesn’t.
One way to make the GNU version of the SED to work on the Mac OS X, is to directly install the gnu-sed along with the default names which will assure you that you won’t have to run different commands on both the operating systems.
In order to install the gnu-sed on the Mac OS X, you can consider the steps shown below.
Command
brew install gnu-sed --with-default-names
This will install the gnu-sed and you can make use of it, the same way you use it in your other Linux machine.
A better solution is to make use of the command that is shown below which is the inplace replace command along with a file extension as the .bak which will help you in achieving the same command for both the Mac OS X and the GNU.
Command
sed -i.bak ‘s/sample/new_sample’ filename
In the above command, the string in the single-quote means that we are replacing the word in a particular file to new_sample.
Now let’s first run the above command on GNU and see how the output turns out to be.
GNU
$ sed --version | head -1 GNU sed version 4.2.2 $ echo 'sample' > 1.txt $ sed -i.bak 's/sample/new_sample/' ./1.txt $ ls 1.txt 1.txt.bak $ cat ./1.txt new_sample
Mac OS X
$ sed --version 2>&1 | head -1 sed: illegal option -- - $ echo 'sample' > 1.txt $ sed -i.bak 's/sample/new_sample/' ./1.txt $ ls 1.txt 1.txt.bak $ cat ./1.txt new_sample
- Related Articles
- Guide to the sed Stream Editor on Linux
- How to substitute an environment variable using sed on Linux?
- Text and File processing using sed Linux Commands
- Recommended IDEs for C# on Windows/Linux/Mac OS
- What is the place value of 5 in the number 3502074 ? (in both figure and words)
- Which are the Best Firewall Software for Windows, Mac, and Linux ?
- What languages have been used to write Windows, Mac OS and Linux OS?
- What is the LD_PRELOAD Trick on Linux?
- How to add a new entry to the PATH variable in ZSH on Mac OS in Linux
- How To Modify MAC address in Windows 10 (Both Wired and Wireless Adapter)?
- What is MAC in Information Security?
- How do you handle End-of-Line characters in Git on Windows / Linux / Mac Operating Systems?
- What is the most compatible way to install python modules on a Mac?
- What are the signs of a malware attack on Mac?
- A vertical tower stands on a horizontal plane and is surmounted by a flag-staff of height \( 7 \mathrm{~m} \). From a point on the plane, the angle of elevation of the bottom of the flag-staff is \( 30^{\circ} \) and that of the top of the flag-staff is \( 45^{\circ} \). Find the height of the tower.
