Unix에서 열 상태에 따라 배경색을 변경하는 방법

Unix에서 열 상태에 따라 배경색을 변경하는 방법

다음 내용이 포함된 파일이 있습니다.

<tr><td>CLNK </td><td>TR-HEH-JFGHG-MTG-N-US-00 </td><td> 841115061</td><td> 9965
<tr><td>CLNM </td><td>TR-HEH-JFGHG-MTG-N-JK-00 </td><td> 841115062</td><td> 9976
<tr><td>CLNKHGKSL </td><td>TR-HEH-JFGHG-MTG-N-US-00 </td><td> 841115063</td><td> 9985
<tr><td>CLNK </td><td>TR-HEH-JFGHG-CRD-N-TR-00 </td><td> 841115064</td><td> 9925
<tr><td>CLNK00 </td><td>TR-HEH-JFGHG-CCS-N-HJ-00 </td><td> 841115065</td><td> 9905
<tr><td>CLNKTYH </td><td>TR-HEH-JFGHG-MTG-N-US-00 </td><td> 841115066</td><td> 9915
<tr><td>CLNKVB </td><td>TR-HEH-JFGHG-MTG-N-MN-00 </td><td> 841115067</td><td> 9935
<tr><td>CLN </td><td>TR-HEH-JFGHG-PLN-N-US-00 </td><td> 841115068</td><td> 9955
<tr><td>CLNK1 </td><td>TR-HEH-JFGHG-MTG-N-US-00 </td><td> 841115069</td><td> 9970

다섯 번째 열 값을 기반으로 다음 출력을 원합니다. 다섯 번째 필드 값이 >9960이면 해당 부분이 아래 문자열로 대체됩니다.

<tr><td>CLNK </td><td>TR-HEH-JFGHG-MTG-N-US-00 </td><td> 841115061</td><td bgcolor="red"> 9965
<tr><td>CLNM </td><td>TR-HEH-JFGHG-MTG-N-JK-00 </td><td> 841115062</td><td bgcolor="red"> 9976
<tr><td>CLNKHGKSL </td><td>TR-HEH-JFGHG-MTG-N-US-00 </td><td> 841115063</td><td bgcolor="red"> 9985
<tr><td>CLNK </td><td>TR-HEH-JFGHG-CRD-N-TR-00 </td><td> 841115064</td><td> 9925
<tr><td>CLNK00 </td><td>TR-HEH-JFGHG-CCS-N-HJ-00 </td><td> 841115065</td><td> 9905
<tr><td>CLNKTYH </td><td>TR-HEH-JFGHG-MTG-N-US-00 </td><td> 841115066</td><td> 9915
<tr><td>CLNKVB </td><td>TR-HEH-JFGHG-MTG-N-MN-00 </td><td> 841115067</td><td> 9935
<tr><td>CLN </td><td>TR-HEH-JFGHG-PLN-N-US-00 </td><td> 841115068</td><td> 9955
<tr><td>CLNK1 </td><td>TR-HEH-JFGHG-MTG-N-US-00 </td><td> 841115069</td><td bgcolor="red"> 9970

답변1

관심 있는 값이 항상 각 행의 마지막 숫자 세그먼트라고 안전하게 가정할 수 있는 경우(예제의 경우) 다음을 수행할 수 있습니다.

$ perl -pe 'm|.*(<td>\s*(\d+)\s*(</td>)?\s*)$|; 
            $cell=$1; 
            $value=$2; 
            if($value > 9960){
                s|$cell|<td bgcolor="red">$value</td>\n|
            }' file 
<tr><td>CLNK </td><td>TR-HEH-JFGHG-MTG-N-US-00 </td><td> 841115061</td><td bgcolor="red">9965</td>
<tr><td>CLNM </td><td>TR-HEH-JFGHG-MTG-N-JK-00 </td><td> 841115062</td><td bgcolor="red">9976</td>
<tr><td>CLNKHGKSL </td><td>TR-HEH-JFGHG-MTG-N-US-00 </td><td> 841115063</td><td bgcolor="red">9985</td>
<tr><td>CLNK </td><td>TR-HEH-JFGHG-CRD-N-TR-00 </td><td> 841115064</td><td> 9925
<tr><td>CLNK00 </td><td>TR-HEH-JFGHG-CCS-N-HJ-00 </td><td> 841115065</td><td> 9905
<tr><td>CLNKTYH </td><td>TR-HEH-JFGHG-MTG-N-US-00 </td><td> 841115066</td><td> 9915
<tr><td>CLNKVB </td><td>TR-HEH-JFGHG-MTG-N-MN-00 </td><td> 841115067</td><td> 9935
<tr><td>CLN </td><td>TR-HEH-JFGHG-PLN-N-US-00 </td><td> 841115068</td><td> 9955
<tr><td>CLNK1 </td><td>TR-HEH-JFGHG-MTG-N-US-00 </td><td> 841115069</td><td bgcolor="red">9970</td>

관련 정보