使用awk/sed/bash切割python输出

时间:2022-06-09 15:42:40

I am attempting to print on separate line or extract all of the following entries:

我正在尝试打印在单独的行或提取所有以下的条目:

['zzb', 'zzc', 'zzd', 'zze', 'zzf', 'zzg', 'zzh', 'zzi', 'zzj', 'zzk', 'zzl', 'zzm', 'zzn', 'zzo', 'zzp', 'zzq', 'zzr', 'zzs', 'zzt', 'zzu', 'zzv', 'zzw', 'zzx', 'zzy', 'zzz']

The same are generated with a python script. I am attempting to pipe all results to a for bash cycle such as:

使用python脚本生成相同的内容。我正在尝试将所有结果传输到一个for bash循环中,例如:

for i in $(python pythonscript.py); do something $i; done

My knowledge on linux commands is sort of basic and I only end up with things such as:

我对linux命令的认识是很基础的,我只知道:

python pythonscript.py | awk -F"'|'" '{print $2}'

but since the entries are printed in a single string, this only gives me a single result.

但是由于条目是在一个字符串中打印的,这只能给我一个结果。

Maybe my python script is incorrect, I would basically like to have a permutation of all 3 letter possible combinations generated from the - A, B, C, D, E, F, G, H, I, L, M, N, O, P, R, S, T alphabet characters that I could later pipe to a for cycle such as:

也许我的python脚本是不正确的,我基本上要所有3字母的排列产生的可能的组合——一个B,C,D,E,F,G,H,我,L,M,N,O,P,R,S T字母字符,我可以以后管等周期:

asd
bcd
ghl
llc
bbo 

However, I do not have the required knowledge and ended up using:

但是,我没有必要的知识,最终使用:

from itertools import product
from string import ascii_lowercase
keywords = [''.join(i) for i in product(ascii_lowercase, repeat = 3)]
print(keywords)

from a different question here on *.

来自另一个关于*的问题。

Any help on the matter will be greatly appreciated.

在这件事上任何帮助都将非常感谢。

1 个解决方案

#1


2  

Don't parse the output with Bash. Change the Python script to print in the format you like.

不要用Bash解析输出。将Python脚本更改为您喜欢的格式。

For example:

例如:

from itertools import product
from string import ascii_lowercase
for t in product(ascii_lowercase, repeat = 3):
    print(''.join(t))

#1


2  

Don't parse the output with Bash. Change the Python script to print in the format you like.

不要用Bash解析输出。将Python脚本更改为您喜欢的格式。

For example:

例如:

from itertools import product
from string import ascii_lowercase
for t in product(ascii_lowercase, repeat = 3):
    print(''.join(t))