0

Continuation of my initial question:

shell script taking input from python program

So I have standard output from my python program being stored in a variable in my shell script. Now, I have to parse this output so that I can take a substring of the last 22 characters. These are the only ones that matter to me. Unfortunately there's no way to really identify these last characters ("keyword=", etc.), meaning I have to do this completely by their position

4

2 に答える 2

1

文字列の最後のN文字が必要な場合は、単純なスライスを使用できます。

>>> v="this is the stdout from my shell command stored in a variable"
>>> v[-22:]
'd stored in a variable'

最後の22文字が返されます。

于 2012-08-30T22:37:42.563 に答える
1

を使用していると仮定するとbash、部分文字列展開を使用できます。

key=$(python ...)   # From  your previous question

suffix=${key: -22}  # The space between : and - is important
于 2012-08-30T22:38:49.937 に答える