質問

I have a file where each line is a list of tuples the following format:

[('a1','b1','c1','d1','e1'), ('a2','b2','c2','d2','e2'), ..., ('an','bn','cn','dn','en')]

n, meaning the list length could be different for each line.

My goal is to extract the first member of each tuple, meaning, I want the following output for each line:

a1 a2 ... an

I would know how to do this if the number of tuples was known, but I can't generalize. Thanks!

役に立ちましたか?

解決

You can use sed:

sed -E "s/[^(]*\('([^']+)'[^(]*/\1 /g; s/ $//" < tuples.txt

Which will produce:

a1 a2 an
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top