0

I have a verilog file that has multiple modules defined containing various input and output variables . I need to find out last occurrence of such variable (input/output) using sed script. I run the following command

address=sed -n '100,200{/output/=};100,200{/input/=}' file.txt
its giving me output as 102 103 104 105 106 while I want only 106. Please suggest me some way.

4

4 回答 4

1

这可能对您有用:

sed '100,200{/input\|output/=};d' file.txt | sed '$!d'

或者也许如你所愿:

address=$(sed '100,200{/input\|output/=};d' file.txt | sed '$!d')
于 2012-07-27T11:54:19.577 回答
0

你可以这样做:

nl -ba < file.txt | sed -n '100,200{/output\|input/h};$x;$p'
于 2012-07-27T15:28:38.690 回答
0
sed -n '100,200p' foo.txt | awk '/input/{s=NR} /output/{s=NR} END{print s}'
于 2012-07-27T10:22:43.183 回答
0

你不必使用 sed,当然 sed/awk 可以做到。尝试这个:

 grep -nE "input|output" test.txt|tail -1|cut -f1 -d:

编辑

你想要这个吗?

kent$  echo "102 103 104 105 106"|awk '{print $NF}'
106

再次编辑

kent$  another=$(echo "102 103 104 105 106"|awk '{print $NF}')

kent$  echo $another
106
于 2012-07-27T10:37:55.120 回答