Sponsored Content
Top Forums Shell Programming and Scripting sed / grep / for statement performance - please help Post 302368661 by TehOne on Thursday 5th of November 2009 09:37:35 AM
Old 11-05-2009
Quote:
Originally Posted by ghostdog74
get rid of all those useless cats, greps and sed.
Code:
find debugme -name "*.txt" | awk 'BEGIN{
   while( (getline line < "debug.files" ) > 0 ) {
       a[++d]=line
   }
   close("debug.files")
}
{
   filename=$0
   while( (getline line < filename ) > 0 ){
       m=split(line,t," ")
       if ( t[1]+0 == t[1]){
           for(i=1;i<=d;i++){
              if( a[i] ~ t[1] ){
                print "found"
                found=1   
              }
           }
       }       
       if(f==0){
        print "not found"
       }
   }
   close(filename)   
}'

NB:not tested.
Your attempt seems to be best when it comes to performance but it doesn't work as it shows not found for each line! I'd appreciate it alot if you could get it working.

Last edited by TehOne; 11-05-2009 at 10:51 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using grep in if statement

Can somebody please guide me towards right syntax: #!/bin/ksh if i = $(grep $NAME filename) echo "Name Found" else echo " Name not Found" fi I need to grep for $NAME in the file, and if it returns false, execute a series of commands and if true, exit out. The above is not the right... (3 Replies)
Discussion started by: chiru_h
3 Replies

2. Shell Programming and Scripting

How to improve grep performance...

Hi All, I am using grep command to find string "abc" in one file . content of file is *********** abc = xyz def= lmn ************ i have given the below mentioned command to redirect the output to tmp file grep abc file | sort -u | awk '{print #3}' > out_file Then i am searching... (2 Replies)
Discussion started by: pooga17
2 Replies

3. 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

4. Shell Programming and Scripting

Grep statement

Hi All, Please can somebody advise that if I want to search a pattern xyz the grep command should only select xyz and not any other pattern containing xyz (ex abxyzcd) Regards (1 Reply)
Discussion started by: Shazin
1 Replies

5. Shell Programming and Scripting

performance of shell script ( grep command)

Hi, I have to find out the run time for 40-45 different componets. These components writes in to a genreric log file in a single directory. eg. directory is LOG and the log file name format is generic_log_<process_id>_<date YY_MM_DD_HH_MM_SS>.log i am taking the run time using the time... (3 Replies)
Discussion started by: vikash_k
3 Replies

6. Programming

Help with improve the performance of grep

Input file: #content_1 12314345345 242467 #content_14 436677645 576577657 #content_100 3425546 56 #content_12 243254546 1232454 . . Reference file: content_100 (1 Reply)
Discussion started by: cpp_beginner
1 Replies

7. Shell Programming and Scripting

Use awk/sed/grep with goto statement!

Hi, I have an array with characters and I am looking for specific character in that array and if those specific character not found than I use goto statment which is define somehwhere in the script. My code is: set a = (A B C D E F) @ i = 0 while ($i <= ${#a}) if ($a != "F" || $a != "D")... (3 Replies)
Discussion started by: dixits
3 Replies

8. Shell Programming and Scripting

Using GREP in IF Statement

Hello All, I have 2 different pieces of code, I am confused why the Code1 is giving me the correct result where as the Code2 is not giving me correct result. It gives me always result as "Failure" irrespective of the "ERROR" word exists in logfile or not. may I know the reason why? I am using Bash... (17 Replies)
Discussion started by: Ariean
17 Replies

9. Shell Programming and Scripting

Performance improvement in grep

Below script is used to search numeric data from around 400 files in a folder. I have 300 such folders. Need help in performance improvement in the script. Below Script searches 20 such folders ( 300 files in each folder) simultaneously. This increases cpu utilization upto 90% What changes... (3 Replies)
Discussion started by: vegasluxor
3 Replies

10. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies
tapset::task(3stap)													       tapset::task(3stap)

NAME
tapset::task - systemtap task tapset DESCRIPTION
task_current The current task_struct of the current task See function::task_current(3stap) for details. task_parent The task_struct of the parent task See function::task_parent(3stap) for details. task_state The state of the task See function::task_state(3stap) for details. task_execname The name of the task See function::task_execname(3stap) for details. task_pid The process identifier of the task See function::task_pid(3stap) for details. pid2task The task_struct of the given process identifier See function::pid2task(3stap) for details. pid2execname The name of the given process identifier See function::pid2execname(3stap) for details. task_tid The thread identifier of the task See function::task_tid(3stap) for details. task_gid The group identifier of the task See function::task_gid(3stap) for details. task_egid The effective group identifier of the task See function::task_egid(3stap) for details. task_uid The user identifier of the task See function::task_uid(3stap) for details. task_euid The effective user identifier of the task See function::task_euid(3stap) for details. task_prio The priority value of the task See function::task_prio(3stap) for details. task_nice The nice value of the task See function::task_nice(3stap) for details. task_cpu The scheduled cpu of the task See function::task_cpu(3stap) for details. task_open_file_handles The number of open files of the task See function::task_open_file_handles(3stap) for details. task_max_file_handles The max number of open files for the task See function::task_max_file_handles(3stap) for details. SEE ALSO
function::task_current(3stap), function::task_parent(3stap), function::task_state(3stap), function::task_execname(3stap), function::task_pid(3stap), function::pid2task(3stap), function::pid2execname(3stap), function::task_tid(3stap), function::task_gid(3stap), function::task_egid(3stap), function::task_uid(3stap), function::task_euid(3stap), function::task_prio(3stap), function::task_nice(3stap), function::task_cpu(3stap), function::task_open_file_handles(3stap), function::task_max_file_handles(3stap), stap(1), stapprobes(3stap) IBM
--- tapset::task(3stap)
All times are GMT -4. The time now is 04:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy