Bash/Scripting/File descriptors

Aus SchnallIchNet
< Bash‎ | Scripting
Version vom 2. Oktober 2009, 09:15 Uhr von Cbs (Diskussion | Beiträge) (Die Seite wurde neu angelegt: ==Playing with several file descriptors== Here is a small example of a shell script using several file descriptors. This script reads a file with the following columns...)

(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu: Navigation, Suche

Playing with several file descriptors

Here is a small example of a shell script using several file descriptors. This script reads a file with the following columns "ip_address trafic_in trafic_out", and writes two files trafic_in and trafic_out.

#!/bin/bash

# open the two output files
exec 6>/tmp/trafic_in.dat
exec 7>/tmp/trafic_out.dat

#open the file containing the data for input.
exec 8</tmp/all_trafic.dat

# data processing
grep -v '^#' <&8 | while read line
do
    set - $(echo $line)
    echo "${1}	${2}" >&6
    echo "${1}	${3}" >&7
done

#close the file descriptors
exec 6<&-
exec 7<&-