Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用python脚本或Shell分割coulmn-in-CSV文件中的文本? 第1行\u 1368083\u美国\u PBPR\u标准 Row215_1368083_US_PBPR_ENH 第216行第60902413行 第227排第37758281排第_Python_Linux_Shell - Fatal编程技术网

如何使用python脚本或Shell分割coulmn-in-CSV文件中的文本? 第1行\u 1368083\u美国\u PBPR\u标准 Row215_1368083_US_PBPR_ENH 第216行第60902413行 第227排第37758281排第

如何使用python脚本或Shell分割coulmn-in-CSV文件中的文本? 第1行\u 1368083\u美国\u PBPR\u标准 Row215_1368083_US_PBPR_ENH 第216行第60902413行 第227排第37758281排第,python,linux,shell,Python,Linux,Shell,最终输出应仅为列中的编号1368083使用str.split s1 = "Row1_1368083_US_PBPR_STD" s2 ="Row215_1368083_US_PBPR_ENH" print(s1.split("_")[1]) print(s2.split("_")[1]) 输出: 1368083 1368083 或者正则表达式 import re s1 = "Row216_60902413_US_PBPR_ENH" s2 ="Row227_37758281_US_PBPR_

最终输出应仅为列中的编号1368083

使用
str.split

s1 = "Row1_1368083_US_PBPR_STD"
s2 ="Row215_1368083_US_PBPR_ENH"

print(s1.split("_")[1])
print(s2.split("_")[1])
输出:

1368083
1368083
或者正则表达式

import re

s1 = "Row216_60902413_US_PBPR_ENH"
s2 ="Row227_37758281_US_PBPR_ENH"

print(re.findall(r"\d{6,}", s1)[0])
print(re.findall(r"\d{6,}", s2)[0])

使用
sed
提取两个'\u'之间的数字部分

sed 's/^.*_\([0-9]*\)_.*/\1/'
或者使用
awk
提取第二个字段,该字段由“\u1”分隔

awk -F'_' '{print $2}'

你应该解释这是如何解决问题的。它适用于例1和例2,而不适用于例3和例4。好吧,我们不应该打印3和4。事实上,从这个问题上看,不是非常清楚,我的假设与你的不同。仅供参考,我没有否决你的答案。请避免“给我密码”的问题,这些问题已经被问了很多次,你必须努力避免找到答案。而是显示您正在处理的脚本,并说明问题所在。也看到
awk -F_ '$2 ~/1368083/{print $2}' file
1368083
1368083