Computing.Net > Forums > Unix > unix or korn

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

unix or korn

Reply to Message Icon

Original Message
Name: htnkd
Date: July 15, 2004 at 08:14:55 Pacific
Subject: unix or korn
OS: linux
CPU/Ram: ?
Comment:

I am currently using fgrep in my scritps to search text files that contain millions of records. I need to print out the strings that starts with '0000000000H' only.

DIRS="AA AB AC AD"
for i in $DIRS
do
fgrep '0000000000H' ${i}.txt > new_${i}.txt
done

Is there a faster way to do this so that only the lines with '0000000000H' are printed.

Seems like this takes forever to run.

Thanks


Report Offensive Message For Removal


Response Number 1
Name: Wolfbone
Date: July 15, 2004 at 09:27:02 Pacific
Reply: (edit)

It should be faster to use an ordinary regexp that includes the '^' beginning of line matcher instead of the fixed-string anywhere in the line method, especially if the lines are long and you can always try the --mmap switch '-)

It is also possible that sed or awk would be faster but you'd have to experiment and the simplicity of the task means that it would be easy to write a c programme which may be worth doing if it's something you'll need to run regularly or often.


Report Offensive Follow Up For Removal

Response Number 2
Name: htnkd
Date: July 15, 2004 at 10:09:07 Pacific
Reply: (edit)


sorry -- it wasn't my grep command it seems the hold up is when I am trying to remove leading and trailing white spaces.

gawk '{printf ("%s|%s|%s|%s|%s\n",substr($0,16,10),substr($0,26,14),substr($0,50,17),substr($0,56,16),substr($0,112,78))}' <test.txt | sed 's/ //g' - | sed 's/ |/|/g' - | sed 's/| /|/g' > new.txt

there is no set tab of white spaces and I do not want to put a "|" in between words in a field.

I thought that maybe using gsub would do it -- but I can't seem to get that to work

anyway of reducing the time in removing leading and trailing spaces in a field.

Thanks


Report Offensive Follow Up For Removal

Response Number 3
Name: htnkd
Date: July 15, 2004 at 10:37:35 Pacific
Reply: (edit)

think I got it

if I use gawk '{gsub( / +/, "");print }' file > newfile

this seems to work
thanks


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 2 Days.
Discuss in The Lounge
Poll History




Data Recovery Software