Performance analysis sed vs awk


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Performance analysis sed vs awk
# 8  
Old 07-06-2012
You can improve the awk program performance dramatically by making it exit after the end of the range. This stops it reading the other three-quarters of the file. I don't know how to get sed to exit early (or if it is possible).

Code:
time awk 'NR > 26000 { exit };(NR>=25000)&&(NR<=26000)' filename

This User Gave Thanks to methyl For This Post:
# 9  
Old 07-06-2012
Good point, the sed version would be:
Code:
sed -n '25000,26000 p; 26000q' filename

# 10  
Old 07-06-2012
Good call on the backticks ; I think the last instance in which I used time for more than one command I was stringing some things together and the backticks were necessary. I still habitually do certain redundant/needless things in scripts, but there's always room to improve.
# 11  
Old 07-06-2012
thank you all for the advice. I'll do some performance analysis over a period of time and post my results here.

Thanks
# 12  
Old 07-06-2012
@zer0sig, the behavior with pipes is unspecified by POSIX, but in ksh "time" times the total time, and I think in bash it does also...
Code:
time sleep 1 | { read; sleep 1 ;} | { read; sleep 1 ;}


Last edited by Scrutinizer; 07-06-2012 at 11:16 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Red Hat

What is the best tools for performance data gathering and analysis?

Dear Guru, IHAC who complaint that his CentOS is getting performance issue. I have to help him out of there. Could you please tell me which tools is better to gathering the whole system performance data? -- CPU/Memory/IO(disk & Network)/swap I would like the tools could be... (6 Replies)
Discussion started by: devyfong
6 Replies

2. Shell Programming and Scripting

Log Analysis with AWK with Time difference

I would like to write a shell script that calculated the time difference bettween the log entries. If the time difference is higher as 200 sec. print the complette lines out. My Problem is, i am unable to jump in the next line and calculate the time difference. Thank you for your Help. ... (5 Replies)
Discussion started by: fabian3010
5 Replies

3. Shell Programming and Scripting

Date and time range extraction via Awk or analysis script?

Hello does anyone know of an awk that will extract log file entries between a specific date and time range, eg: awk '/15\/Dec\/2010:16:10:00/, /15\/Dec\/2010:16:15:00/' access_log but one that works? Or a free command line log file analysis tool/script? I'd like to be able to view... (2 Replies)
Discussion started by: competitions
2 Replies

4. Linux

Routing table vulnerability comparison between two versions and analysis of performance in a scenari

Hi Routing tables in a typical linux kernel are implemented using hash data structures. So if the hash table is forced to behave more like a linked list(i.e create chaining) the purpose of using hash is defeated and time complexity increases. I want to try to assess the performance deterioration... (0 Replies)
Discussion started by: coolvaibhav
0 Replies

5. Shell Programming and Scripting

Increase sed performance

I'm using sed to do find and replace. But since the file is huge and i have more than 1000 files to be searched, the script is taking a lot of time. Can somebody help me with a better sed command. Below is the details. Input: 1 1 2 3 3 4 5 5 Here I know the file is sorted. ... (4 Replies)
Discussion started by: gpaulose
4 Replies

6. UNIX for Advanced & Expert Users

WEB Server Log File Analysis using awk/sed/grep

I'm trying to find a way to show large page sizes (page size in K) from multiple web server log files. Essentially I want to show only rows from a file where a specific column is larger than some value. Has anyone ever done this type of log analysis? If so, a snippet of code would be very... (2 Replies)
Discussion started by: mike_cataldo@ad
2 Replies

7. UNIX for Advanced & Expert Users

sed performance

hello experts, i am trying to replace a line in a 100+mb text file. the structure is similar to the passwd file, id:value1:value2 and so on. using the sed command sed -i 's/\(123\):\(\{1,\}\):/\1:bar:/' data.txt works nicely, the line "123:foo:" is replaced by "123:bar:". however, it takes... (7 Replies)
Discussion started by: f3k
7 Replies

8. Shell Programming and Scripting

AWK script: decrypt text uses frequency analysis

Ez all! I have a question how to decrypt text uses letter frequency analysis. I have code which count the letters, but what i need to do after that. Can anybody help me to write a code. VERY NEEDED! My code now: #!/usr/bin/awk -f BEGIN { FS="" } { for (i=1; i <= NF; i++) { if ($i... (4 Replies)
Discussion started by: SerJel
4 Replies
Login or Register to Ask a Question