Convert sed to perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert sed to perl
# 1  
Old 04-22-2010
Convert sed to perl

Can anyone convert this from sed to perl:

Code:
sed -n '/\var\/log/p' /etc/syslog.conf

I think Ive looked at this to much....urgh..

Thanks
Ben

Last edited by pludi; 04-22-2010 at 03:55 AM..
# 2  
Old 04-22-2010
Did you meant to convert

Code:
sed -n '/\/var\/log/p' /etc/syslog.conf

# 3  
Old 04-22-2010
Im sorry I dont understand what your asking. I need to convert it from sed to a perl command.

Thanks
Ben
# 4  
Old 04-22-2010
Try this,

Code:
perl -nle "print if(/\/var\/log/)" /etc/syslog.conf

# 5  
Old 04-22-2010
In your code you are trying to print /var/log.
But in your first post you didn't escape the slash properly.
That is the question from Mr.devtakh

Last edited by thillai_selvan; 04-22-2010 at 03:05 AM..
# 6  
Old 04-22-2010
What your sed is doing is printing all the lines which has /var/log in it (emulates "grep").

Now to do same easiest way is

perl -nle 'print if /pattern/' file(s)

so kind of one liner in perl.
Code:
$ perl -nle 'print if /\var\/log/' /etc/syslog.conf

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl to shell convert

HI All, I am new in shell scripting ,can any one please help me to convert this scripts from Perl to Shell. Thank in advance. $customer=$ARGV; $rows=`hadoop fs -ls /ncip/$customer/|wc -l`; if($rows==3){ print "$customer directory exists , cleaning up ! \n"; `hadoop fs -rm... (1 Reply)
Discussion started by: Atul301
1 Replies

2. Shell Programming and Scripting

Rewrite sed to perl or run sed in perl

I am having trouble re-writing this sed code sed -nr 's/.*del(+)ins(+).*NC_0{4}(+).*g\.(+)_(+).*/\3\t\4\t\5\t\1\t\2/p' C:/Users/cmccabe/Desktop/Python27/out_position.txt > C:/Users/cmccabe/Desktop/Python27/out_parse.txt in perl Basically, what the code does is parse text from two fields... (12 Replies)
Discussion started by: cmccabe
12 Replies

3. Shell Programming and Scripting

Convert perl to shell

Hi I am a novice in scripting .Please help me converting perl script into shell my ($ref) = shift; my $id; my $cnt=0; my $first =0; my $filename ; my $filename1 ; FOREACH:foreach my $r (qw(RET LSH PDM )) { $ref->{$cnt}->{num_errors} =0; $ref->{$cnt}->{num_warnings} =0;... (2 Replies)
Discussion started by: apassi
2 Replies

4. Shell Programming and Scripting

Convert UNIX to perl

Hi, Can someone convert the code into perl ? x=(a b c) y=(d e) times=$((${#x} * ${#y})) ((xi=yi=0)) for((i=1;i<=times;i++,xi++,yi++)) do if((xi>${#x}-1));then xi=0;fi if((yi>${#y}-1));then yi=0;fi print ${x},${y} done (4 Replies)
Discussion started by: giri_luck
4 Replies

5. Shell Programming and Scripting

Convert to Hex in perl

Hi, i want to convert number 5860533159 to hexadecimal. i need to use perl. i used $foo = 5860533159; $hexval3 = sprintf("%#x", $foo); i am getting value as 0xffffffff. i need to get value as 0x15D50A3A7. when i converted using google calculator, i got the correct value, expected... (9 Replies)
Discussion started by: asak
9 Replies

6. Shell Programming and Scripting

HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

Hi all, Not sure if this should be in the programming forum, but I believe it will get more response under the Shell Programming and Scripting FORUM. Am trying to write a customized df script in Perl and need some help with regards to using arrays and file handlers. At the moment am... (3 Replies)
Discussion started by: newbie_01
3 Replies

7. Shell Programming and Scripting

Convert from Csh to Perl

Hi , I am trying to convert the below code embedded in a csh script to Perl. Can any expert give me some advice on this ? sed -n ''"$start_line"',$ p' $tester_dir/nfiles_extracted.txt|cut -c1-4,6-|/bin/perl $test_summary/compare_for_all _Duts.pl|sort > $tester_dir/nfiles_extracted1.txt (0 Replies)
Discussion started by: Raynon
0 Replies

8. Shell Programming and Scripting

Convert Sed command to perl command

Hello, Can any perl experts help me convert my sed string to perl. I am unsuccessful with this. I have to remove this string from html files OAS_AD('Top'); I have come up with this. However the requirement is in perl. for find in $(find . -type f -name "file1.html") ; do cat $find |... (2 Replies)
Discussion started by: abacus
2 Replies

9. Shell Programming and Scripting

Convert .sh script into perl

Good afternoon to you all I really need your help I have the following script developed in .sh and I need to convert it into perl. Can someone help me do it please? Here´s the script: ############################################## ############################################## ... (3 Replies)
Discussion started by: zarahel
3 Replies

10. Shell Programming and Scripting

***convert from perl to bash***

can any body translate the follwing script into one that works in bash? #!/usr/bin/perl # classify_books.pl my $csv_file = shift; my %categories = ( 'childrens' => 'childrens_books.txt', 'horror' => 'horror_books.txt', 'sports ' =>... (3 Replies)
Discussion started by: ferrycorsten73
3 Replies
Login or Register to Ask a Question