CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
sed in perl


New User

Feb 21, 2014, 6:11 AM

Post #1 of 3 (2564 views)
sed in perl Can't Post

Hi all

I have this sed command that works find on the command line but when i call it from a perl script is errors

sed -i '13 i <key>AllowClearTextPasswords</key>\n<true/>' file.txt

i get this error

sed: -e expression #1, char 41: unknown command: `<'

Any ideas? i have tired escaping the < but i dont think i had it right

Veteran / Moderator

Feb 21, 2014, 10:05 AM

Post #2 of 3 (2554 views)
Re: [ab52] sed in perl [In reply to] Can't Post

Please show how you call it from Perl. I can't answer without that.

But the main point is that there is no point calling a sed command from Perl, since Perl can do everything that sed can do, and it can do it better and il most cases faster. You should do it in Perl.

New User

Feb 24, 2014, 12:46 AM

Post #3 of 3 (2539 views)
Re: [Laurent_R] sed in perl [In reply to] Can't Post

this is my code

my $searchterm=`defaults read /Users/$USER/Library/Preferences/ | grep -w "AllowClearTextPasswords = 1"`; 
if ( $? !=0 ) {
_log("Converting to xml ");
system("plutil -convert xml1 /Users/$USER/Library/Preferences/");
_log("Adding in the correct line");
my $cmd = "/apps/MacOS/ports/10.8/libexec/gnubin/sed -i '13 i <key>AllowClearTextPasswords</key>\n<true/>' /Users/$USER/Library/Preferences/";


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives