Replacing Awk with One-liner Perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing Awk with One-liner Perl
# 8  
Old 12-23-2011
Quote:
Originally Posted by balajesuri
Ok.. What happened? Isn't the perl one-liner working?


unfortunately, it didn't work. it also just sat there.

maybe you know of a better way to do this. if i can do what i want with anything other than having to write a perl script, i'd be very content.

meaning, maybe a combination of sed, awk, etc can accomplish this. i'd think a perl oneliner should be able to do it though.
# 9  
Old 12-23-2011
I do not understand. It works fine for me.

Code:
user@ubuntu:~/programs$ cat input
Dec 22 19:52:59 This is the zeroth line of the log. This is not so great. I am not so happy.
Dec 23 20:54:84 This is the first line of the log.  This is great. I am so happy.
Dec 23 20:54:14 This is the sec line of the log.  This is great. I am so happy.
Dec 23 20:54:14 This is the thir line of the log.  This is great. I am so happy.
Dec 23 20:54:14 This is the fou line of the log.  This is great. I am so happy.
Dec 23 20:54:14 This is the fifth line of the log.  This is great. I am so happy.
Dec 24 05:22:59 This is the sixth line of the log. This is great. I am so happy.

user@ubuntu:~/programs$ perl -ne '(/^Dec 23/)&&($p=1);($p==1)&&(print)' input
Dec 23 20:54:84 This is the first line of the log.  This is great. I am so happy.
Dec 23 20:54:14 This is the sec line of the log.  This is great. I am so happy.
Dec 23 20:54:14 This is the thir line of the log.  This is great. I am so happy.
Dec 23 20:54:14 This is the fou line of the log.  This is great. I am so happy.
Dec 23 20:54:14 This  is the fifth line of the log.  This is great. I am so happy.
Dec 24 05:22:59 This is the sixth line of the log. This is great. I am so happy.

This User Gave Thanks to balajesuri For This Post:
# 10  
Old 12-24-2011
Quote:
Originally Posted by balajesuri
I do not understand. It works fine for me.

Code:
user@ubuntu:~/programs$ cat input
Dec 22 19:52:59 This is the zeroth line of the log. This is not so great. I am not so happy.
Dec 23 20:54:84 This is the first line of the log.  This is great. I am so happy.
Dec 23 20:54:14 This is the sec line of the log.  This is great. I am so happy.
Dec 23 20:54:14 This is the thir line of the log.  This is great. I am so happy.
Dec 23 20:54:14 This is the fou line of the log.  This is great. I am so happy.
Dec 23 20:54:14 This is the fifth line of the log.  This is great. I am so happy.
Dec 24 05:22:59 This is the sixth line of the log. This is great. I am so happy.

user@ubuntu:~/programs$ perl -ne '(/^Dec 23/)&&($p=1);($p==1)&&(print)' input
Dec 23 20:54:84 This is the first line of the log.  This is great. I am so happy.
Dec 23 20:54:14 This is the sec line of the log.  This is great. I am so happy.
Dec 23 20:54:14 This is the thir line of the log.  This is great. I am so happy.
Dec 23 20:54:14 This is the fou line of the log.  This is great. I am so happy.
Dec 23 20:54:14 This  is the fifth line of the log.  This is great. I am so happy.
Dec 24 05:22:59 This is the sixth line of the log. This is great. I am so happy.

my fault. your command actually works. it just doesn't work well on huge log files. apparently when i thought that it was hanging it was just taking a while to read through all the logs for the strings i asked it to look for.

looks like awk might be the fastest way to do this then. Smilie i was hoping there was something faster.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Perl one liner in bash script not replacing hours and minutes [HH:MM]

Hi I want to replace time stamp in the following line PROCNAME.Merge.exchMon.CODE.T_QSTART 08:45 read assuming the new time stamp is 09:45 ; the line is getting replaced as below :45 read I'm trying to use the perl one liner in bash script perl -pi... (4 Replies)
Discussion started by: charlie87
4 Replies

2. Shell Programming and Scripting

Checking and replacing first line in text file, one-liner?

Hello, I'm looking to check only the first line of a file to see if it is a format string, like # -*- coding: utf-8; mode: tcl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -\*- vim:fenc=utf-8:ft=tcl:et:sw=2:ts=2:sts=2if the first line is anything else, insert the above string. I'd... (3 Replies)
Discussion started by: f77hack
3 Replies

3. Shell Programming and Scripting

PERL one liner

hi, I am using PERL one liner for oracle database connection as : $PERL -e "use DBI; DBI->connect(qw(DBI:Oracle:SID user passwd));" is there a way to append select statement to this connection ? i.e. DB connection and select stmt in one line ? how to do sysdba connection using one lines... (1 Reply)
Discussion started by: talashil
1 Replies

4. Shell Programming and Scripting

Replacing lines matching a multi-line pattern (sed/perl/awk)

Dear Unix Forums, I am hoping you can help me with a pattern matching problem. What am I trying to do? I want to replace multiple lines of a text file (that match a multi-line pattern) with a single line of text. These patterns can span several lines and do not always have the same number of... (10 Replies)
Discussion started by: thefang
10 Replies

5. Shell Programming and Scripting

HELP with AWK one-liner. Need to employ an If condition inside AWK to check for array variable ?

Hello experts, I'm stuck with this script for three days now. Here's what i need. I need to split a large delimited (,) file into 2 files based on the value present in the last field. Samp: Something.csv bca,adc,asdf,123,12C bca,adc,asdf,123,13C def,adc,asdf,123,12A I need this split... (6 Replies)
Discussion started by: shell_boy23
6 Replies

6. Shell Programming and Scripting

replace awk with a perl one liner (REGEXP and FS)

hello, I want to replace awk with a perl one liner in unix. i use in awk REGEX and FS ( field separator) because awk syntaxes in different unix os versions have not the same behaviour. Awk, Nawk and GNU Awk Cheat Sheet - good coders code, great reuse i have a file named "file" and want... (5 Replies)
Discussion started by: bora99
5 Replies

7. Shell Programming and Scripting

Need an awk / sed / or perl one-liner to remove last 4 characters with non-unique pattern.

Hi, I'm writing a ksh script and trying to use an awk / sed / or perl one-liner to remove the last 4 characters of a line in a file if it begins with a period. Here is the contents of the file... the column in which I want to remove the last 4 characters is the last column. ($6 in awk). I've... (10 Replies)
Discussion started by: right_coaster
10 Replies

8. Shell Programming and Scripting

Search & Replace regex Perl one liner to AWK one liner

Thanks for giving your time and effort to answer questions and helping newbies like me understand awk. I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk. Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Discussion started by: verge
9 Replies

9. Shell Programming and Scripting

awk/perl one-liner assist

In a ~4GB file there are lines like, 13.13.4.3 Googe.com - Jan/23/2011:00:00:00 +0000 "URL Google HTTP/1.1" 45 56 208 - "http://www.gogle.com/webhp?hl=en&tab=nw#hl=en&source=hp&biw=1366&bih=667&q=hello&aq=f&aqi=&aql=&oq=&fp=c432485467934a89" ".Net; Fox" - 13.145.3.3 Goge.com -... (3 Replies)
Discussion started by: gameboy87
3 Replies

10. Shell Programming and Scripting

Perl One Liner

Hi , Can anybody explain how this perl one liner works.. It is to test whether the number is prime or not perl -le 'print "PRIME" if (1 x shift) !~ /^(11+)\1+$/' 19 Thanks in advance Shihab (2 Replies)
Discussion started by: shihabvk
2 Replies
Login or Register to Ask a Question