2012-03-23 3 views

답변

2

awk 사용 :

sed -nf script.sed infile 

그리고 출력

내용 script.awk을의 :

awk -f script.awk infile 

그리고 출력 :

text 
33 xxx 7 
more text 
33 zzz 3 
55 n 
33 yyy 5 
66 asf sdf 

스크립트 실행

$1 ~ /^[[:digit:]]+$/ && $2 ~ /^[xyz]{3}$/ && $3 ~ /^[[:digit:]]+$/ { 
    num = $1 
    digits = digits " " $3 
} 

END { 
    print num digits 
} 

내용 infile

33 7 3 5 
2

한 방법으로 sed :

콘텐츠의 script.sed :

의 23,516,

내용 :

text 
33 xxx 7 
more text 
33 zzz 3 
55 n 
33 yyy 5 
66 asf sdf 

스크립트를 실행 :

33 7 3 5 
1

을이 당신을 위해 작동 될 수 있습니다

sed '/^\([0-9]\+ \)[xyz]\{3\} \([0-9]\+\)/{s//\1\2/;H};$!d;g;s/.//;s/\n[0-9]*//g' file 
33 7 3 5 
관련 문제