티스토리 뷰

IoT 과정

HPUX - Pipes

gaelim 2017. 6. 22. 12:30
반응형

Pipelines

The | symbol is used for linking two commands together. 

A | B | C   [commands B must be filter]

{

$ who | wc -l

14

$ who | date

Thu Jun 22 12:12:12 KST 2017

$ ps -ef | more

$ ls | sort -r | more

$ ps -ef | grep telnetd

$ ps -ef | grep telnetd | wc -l

}


Pipelines versus Input and Output Redirection

who > sort.out, sort < who.out  versus. who | sort


Redirection in a Pipeline  (stdout - pipe line-> stdin)

$ grep user /etc/passwd | wc -l > wc.out      [good]

$ grep user /etc/passwd > grep.out | wc -l    [bad]

$ grep user /etc/passwd 2> grep.err | wc -l   [good or bad]

$ grep user /etc/passwd | wc -l < /etc/passwd [bad]

$ grep user /etc/passwd | wc -l 2> wc.out     [good]


cut command

$ date | cut -c1-3                      [characters 1~3]

$tail /etc/passwd | cut -f1,6 -d:     [field ":" 1, 6]

$ who | cut -f1 -d" "                  [field  " "1]

user8

user5

user9

user6

user7

user1


tr command

Translate character 

$ tr "a" "@" < filenames

$ who | tr -s " " | cut -f1,5 -d" "  // -s 반복되는 문자를 하나로 바꿈

user8 11:54

user5 10:41

user9 09:24

user6 09:41


awk command

field cut [work as tr | cut]

$ who | awk '{ print $1,$3}'
user8 Jun
user5 Jun
user9 Jun
user6 Jun
user7 Jun
user1 Jun

$ bdf | awk '{ print $5,$6}'
%used Mounted
23% /
10% /stand


tee command

Tap the pipeline, print and stdout

$ tee 123.out 
393828       //ctrl +d
393828       //print
$ cat 123.out  
393828      //saved

$ who | tee who.out | wc -l
14
$ cat who.out
user8      pts/ta       Jun 22 11:54
user5      pts/0        Jun 22 10:41
user9      pts/tb       Jun 22 09:24
user6      pts/1        Jun 22 09:41

$ who | tee who.out ; cat who.out | wc -l

user8      pts/ta       Jun 22 11:54

...

user5      pts/tl       Jun 22 12:15

14


$ who | tee who.out | wc -l ; cat who.out

14

user8      pts/ta       Jun 22 11:54

user5      pts/0        Jun 22 10:41

...


pr command


$ cut -f1 -d: /etc/passwd | pr -t -5

root          hpdb          iwww          user7         user16

instr         nobody        owww          user8         user17

daemon        www           tftp          user9         user18



반응형

'IoT 과정' 카테고리의 다른 글

HPUX - Shell Programming  (0) 2017.06.23
HPUX - Process Control  (0) 2017.06.22
HPUX - Input and Output Redirection  (0) 2017.06.22
HPUX - Quoting  (0) 2017.06.21
HPUX - File Name Generation  (0) 2017.06.21