문제

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