user1553248
user1553248

Reputation: 1204

parsing stdout in shell script

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

Upvotes: 0

Views: 368

Answers (2)

gabrtv
gabrtv

Reputation: 3588

If you need the last N characters of a string, you can use a simple slice:

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

The last 22 chars are returned.

Upvotes: 1

chepner
chepner

Reputation: 531758

Assuming you are using bash, you can use substring expansion:

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

suffix=${key: -22}  # The space between : and - is important

Upvotes: 1

Related Questions