문제

Change "<path>" value with different string depends on last line. In that case when see in the last line "*" to replace "<path>" with "ls -lrt" and to separate the "*" from the last line when see slash for anything else with "find".

Text file:

<path>/etc/inet.d/*.conf
<path>/etc/rc/*
<path>/etc/rc*

Expect View:

find /etc/inet.d/*.conf
ls -lrt /etc/rc/ *
ls -lrt /etc/rc*
도움이 되었습니까?

해결책

I think you mean last character of each line, not last line!

if it is right, check this out:

awk '{if($0~/\*$/)sub(/<path>/,"ls -lrt ");else sub(/<path>/,"find ")}7' file

with your data:

kent$  echo "<path>/etc/inet.d/*.conf
<path>/etc/rc/*
<path>/etc/rc*"|awk '{if($0~/\*$/)sub(/<path>/,"ls -lrt ");else sub(/<path>/,"find ")}7' 
find /etc/inet.d/*.conf
ls -lrt /etc/rc/*
ls -lrt /etc/rc*
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top