built in unix / linux command for recursive find and replace? - linux

Many people string together find and sed, or perl, or any number of other unix commands to find and replace across multiple files. But, there's a simple command that can do it for you without the hassle?
Edit:
The Digital Ninja points out that it's rpl.
However this is not a built in command but, for debian based distros like Ubuntu you can simply install it with
sudo apt-get install rpl
I would guess that it's available through most package managers in other *nix OSs.
OS X Users can download a binary at
http://www.laffeycomputer.com/rpl.html

I belive you are thinking of 'rpl'
http://www.linux.org/apps/AppId_2684.html

I think some variation of the following would work :
find . -name *.extension | perl -pi.bak -e "s/text_to_be_replaced/replacement/"

Related

shell cmd transfair windows cmd

I have a regexp using grep which I use to get the latest directory matching it.
Any chance I get a equivalent command as the one below to work on a windows machine?
ls | grep -E "20[0-9]{2}-[0-1][0-9]-[0-3][0-9]-[0-9]{0,5}" | tail -1
I would appreciate any help.
Installing cygwin will give you a nearly linux like shell environment. When you set the cygwin bin into your windows PATH you can even build the pipe like that in a CMD. I can't say anything about the unix like stuff that newer windowses are supposed to bring along though.

Cannot find chmod[metasploit installation]

in the picture below you can see that it says chmod command is not found yet it has chmod installed. I am installing metasploit directly from the terminal(I did not install any desktop environment and don't want to run msf from there). Is there any way to solve this? I would gladly appreciate any replies.
Instead of using that command, use this instead
curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > msfinstall && chmod 755 msfinstall && ./msfinstall
Remove the backslashes from the composite Bash command, they're used in Linux to escape the space character. For example, ỳou would have to type:
cd ~/Documents/My\ Folder
to access
~/Documents/My Folder
By writing the command the way you did you were looking for the ' chmod' command instead of 'chmod', you've basically inserted a space before the command name.
I'd suggest studying Linux Bash scripting before venturing into Metasploit.
You would otherwise continually stumble against this kind of issues, also if you'd like to work with Metasploit from its command console it's pretty much mandatory to study Linux Bash scripting (and the Linux OS as a whole).

linux string-replace for mac os x i.e. sed with no regex

i have an old script on which replaces strings in files using the 'replace' command e.g.
newname=`echo "$f" | replace "${OLD}" "${NEW}"`
this used to run on mac os x (all versions up to yosemite). I remember finding this as a non-regex processing version of sed i.e. you don't need to escape all the regex bits of the string. it definitely exists under linux (http://linux.die.net/man/1/replace).
i had to rebuild my mac (os x yosemite) and cannot for the life of me find this command. have tried
googling but everything points to sed!
tried some of the gnu utility packages in brew e.g. coreutils
nothing - i'm sure it used to exist!?
any pointers gratefully received!

Linux command to DOS

I have a file include some linux command and I want to run in on windows (DOS command).
The command is:
cat tmp/$id/index.html | sed -e 's/ID/$id/g' > a;mv a tmp/$id/index.html
What is the similar command in MS-DOS?
Thank you!
The problem is that natively there is no equivalent command to sed. You have two options from my point of view. Either create a vb script that does what you want (It will not take 1 line though - more like 10-15 I guess), or use something like GnuWin32 that gives you the option to run unix commands in windows terminal.
You could consider using powershell to do approximately the same thing. It supports cat and mv and you can get a sed like equivalent by using %{_ -replace "expression", "replace"}. Details here http://blogs.msdn.com/b/zainnab/archive/2007/07/09/grep-and-sed-with-powershell.aspx
Or consider using a linux like command prompt like bash which should be available through cygwin
I think this is impossible to do in "bare" command line (as you called DOS command), because cat and sed are separate utilities. If you want to port this script from Linux command shell to windows command line, I would advise you to download and install CygWin
DOS itself does not have support for that. You could try with a port of SED for DOS available here. If you can get Powershell, that's an option. Here's an example of using grep/sed with Powershell.
There are many options.
You can try to install cygwin or download and install Git and use Git-bash or add the bin directory to your PATH so you can run this command on your CMD prompt.
There is no such command(s) for MS-DOS.

Perl module or method to create DVD compliant ISO from directory without system commands

Are there any Perl modules or combination of modules to create DVD compliant ISOs? This will run on Linux and I'm not concerned about portability. What I'm looking to do is create a DVD compliant ISO from a directory that contains a VIDEO_TS directory structure. The solution would not need to rip an actual DVD.
What I currently run is:
genisoimage -V 'Name_of_DVD' -dvd-video -o dvd.iso /some_directory
I am aware of Perl ability to run external commands:
system function
exec function
backticks (``) operator
open function
There is also CPAN the CPAN module Filesys::MakeISO::Driver::Mkisofs which uses genisoimage/mkisofs. What I specifically want is a solution that does NOT use linux/OS commands. If there are no such solutions or the solution is overly complex then please state that. Thanks.
While I share the enthusiasm for CPAN, I think that if there isn't something obvious that works, and you don't care about portability away from linux, then I would just do
use strict;
use warnings;
use autodie;
...
system( q# genisoimage -V 'Name_of_DVD' -dvd-video -o dvd.iso /some_directory # );
or as you mention, use Filesys::MakeISO::Driver::Mkisofs.
Not trying to be snarky, but CPAN is supposed to be productivity++, but if it doesn't exist, then do what works.

Resources