How can I avoid using temp files in Korn Shell?

How can I avoid using temp files in Korn Shell?

Post by bdb.. » Tue, 11 Apr 2000 04:00:00



I am running netstat one time and need to grep the output several times
for my final output.

I am currently writing the output of netstat to a temp file and then
grepping through that.

This seems sloppy to me. It would be nice is I could write the netstat
output to memory.

Does anyone know how this can be done?

(P.S. netstat takes a while to complete, so running it once for each
grep is out of the question)

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

How can I avoid using temp files in Korn Shell?

Post by Dan Merc » Tue, 11 Apr 2000 04:00:00




> I am running netstat one time and need to grep the output several times
> for my final output.

> I am currently writing the output of netstat to a temp file and then
> grepping through that.

> This seems sloppy to me. It would be nice is I could write the netstat
> output to memory.

> Does anyone know how this can be done?

> (P.S. netstat takes a while to complete, so running it once for each
> grep is out of the question)

> Sent via Deja.com http://www.deja.com/
> Before you buy.

You should probably be running netstat once through a read loop
and storing the information you need in arrays,  then processing
the arrays.  The extended globbing available in the Korn shell
can actually be more powerful that regular expressions since it
incorporates NOT logic and allows deep embedding of nested
expressions.

It would help better if we knew what info you were trying to assemble.

--
Dan Mercer

Opinions expressed herein are my own and may not represent those of my employer.

 
 
 

How can I avoid using temp files in Korn Shell?

Post by Barry Margoli » Tue, 11 Apr 2000 04:00:00



>I am running netstat one time and need to grep the output several times
>for my final output.

>I am currently writing the output of netstat to a temp file and then
>grepping through that.

>This seems sloppy to me. It would be nice is I could write the netstat
>output to memory.

>Does anyone know how this can be done?

netstat_output="`netstat ...`"

When you need to grep through this, you do:

echo "$netstat_output" | grep ...

--

Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

How can I avoid using temp files in Korn Shell?

Post by Charles Dem » Wed, 12 Apr 2000 04:00:00





>>I am running netstat one time and need to grep the output several times
>>for my final output.

>>I am currently writing the output of netstat to a temp file and then
>>grepping through that.

>>This seems sloppy to me. It would be nice is I could write the netstat
>>output to memory.

>>Does anyone know how this can be done?

>netstat_output="`netstat ...`"

>When you need to grep through this, you do:

>echo "$netstat_output" | grep ...

Or you could use egrep to grep on multiple patterns:

nstat ... | egrep '(pattern1)|(pattern2)|...|(patternn)'

or use awk to grep and output to multiple files like this:

nstat ... | awk '/pattern1/ {print >> "file1"; close("file1")}
                 /pattern2/ {print >> "file2"; close("file2")}
                 .
                 .
                 .
                 /patternn/ {print >> "filen"; close("filen")}'

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.

 
 
 

1. avoiding temp files

I have a very large file with two fields on each line. I want to prepend,
to each line, the total number of lines in the file that start with the
same word as that line.

For example if the file contained

word1 fyslgdkv
word1 ghsnkfdvj
word1 dfhnglk
word2 nvhjdlk
word3 bhvjklsflkhgb
word3 yuskdufhg
word3 xkdu
word3 hdfvygukhfds

I would like the new file to contain

3 word1 fyslgdkv
3 word1 ghsnkfdvj
3 word1 dfhnglk
1 word2 nvhjdlk
4 word3 bhvjklsflkhgb
4 word3 yuskdufhg
4 word3 xkdu  
4 word3 hdfvygukhfds

I know how to do this, but not without creating 2 new files--and there's
not room enough on my system disk for that, with the size of file I start
off with. This is how I would do it for a smaller file:

bash-2.04$ sort file1 > file2
bash-2.04$ rm file1
bash-2.04$ awk '{print $1}' file2 | uniq -c > file3
bash-2.04$ join -1 2 -2 1 -o 1.1,2.1,2.2 file3 file2 > file1

Can someone help me to get the same result without the system needing to
hold three huge files at the same time?

Thanks --Jon

2. Study network on Scholarship...

3. best korn shell resources and is there a korn shell faq

4. trap --append 'new_action' exit ?

5. how to clean up the old files using korn shell

6. Number 9 Graphics Card/Yggdrasil Linux Failing

7. displaying free disk disk block and files in korn shell using df

8. NTFS recovery tool for linux?

9. Newbie help with Shell scripts (using Korn shell)

10. Write to 2 file from pipe without using temp file

11. How to attach file to EMAIL MESSAGE within shell script(Korn shell)

12. Updating files using a temp file: Invalid cross-device link error

13. Compare file modification date using tcsh built-ins