Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.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
需要Unix中文本字段1中最后一个逗号后的数据_Unix - Fatal编程技术网

需要Unix中文本字段1中最后一个逗号后的数据

需要Unix中文本字段1中最后一个逗号后的数据,unix,Unix,您需要以下查询的帮助 $cat sample.txt 414d51204d5150525447575648415050529a6af298e,,,002330618820140707134048 ,+0657,45675 414d51204d514e55533732355051543051696344201645c6,002330618820140707134048 ,+0657,tgre,ghty 需要字段1中最后一个逗号后的所有字段。正如您所看到的,有很多414D51204D51505

您需要以下查询的帮助

$cat sample.txt

414d51204d5150525447575648415050529a6af298e,,,002330618820140707134048  ,+0657,45675
414d51204d514e55533732355051543051696344201645c6,002330618820140707134048  ,+0657,tgre,ghty
需要字段1中最后一个逗号后的所有字段。正如您所看到的,有很多414D51204D515052547575648415050529A6AF298E、、,,, 输出必须如下所示

预期产出:

002330618820140707134048  ,+0657,45675
002330618820140707134048  ,+0657,tgre,ghty
感谢使用egrep或grep-E:

使用普通grep:

输出:

002330618820140707134048  ,+0657,45675
002330618820140707134048  ,+0657,tgre,ghty
002330618820140707134048  ,+0657,45675
002330618820140707134048  ,+0657,tgre,ghty
或使用sed:

或者只是关于空间:

sed -e 's/^[^ ]\+,//' your_file

您可以使用shell程序

cat sample.txt | sed -n 1'p' | tr ',' '\n' | while read word; do
echo $word
done

如果其他方法不起作用,这里有一个perl oneliner:

perl -lne 'print $1 if /.*?,+(.*)/'
输出:

002330618820140707134048  ,+0657,45675
002330618820140707134048  ,+0657,tgre,ghty
002330618820140707134048  ,+0657,45675
002330618820140707134048  ,+0657,tgre,ghty
您可以使用sed和cut:

sed删除空字段 剪切以选择所需字段 例如:


你好,伙计,grep-o选项在我的unix boxsunos中不可用。我会给我任何其他选择。感谢你没有得到想要的输出。O/p获得414D51204D5150525475648415050529A6AF298E、、002330618820140707134048、+065745675 414D51204D514E5533732355051543051696344201645C6002330618820140707134048、+0657,tgre、,ghty@user3847566你试过所有sed命令了吗?O/p是什么意思?不走运。同样的问题,我不一定会在field2中获得+。但我想要字段1中最后一个逗号之后的所有字段。@user3847566您的文件真的包含多行吗?嗨,伙计,我得到下面的错误。perl-lnE'print$1 if/*?,+.*/'sample.txt无法识别的开关:-E-h将显示有效选项。@user3847566 try-lnE而不是-lnEHi Mate,我在字段2中不一定会得到+。但是字段1有逗号,我想要字段1中最后一个逗号之后的所有字段这不是我的cmd所做的吗?还是我误解了你?sed中的My+表示我得到的一个或多个命令输出是cat sample.txt | sed's/,+/,/g'| cut-d','-f2-,,0023306188201407071340480657,,45675 0023306188201407071340480657,tgre,ghty。此外,sed-r在我的unix系统中是非法选项
perl -lne 'print $1 if /.*?,+(.*)/'
002330618820140707134048  ,+0657,45675
002330618820140707134048  ,+0657,tgre,ghty
sed -r 's/,+/,/g' < text.txt | cut -d',' -f2-
002330618820140707134048  ,+0657,45675
002330618820140707134048  ,+0657,tgre,ghty