Unix 查找下一个分隔符ksh

Unix 查找下一个分隔符ksh,unix,ksh,separator,Unix,Ksh,Separator,我有一个由假脱机创建的文件。此文件包含用分隔符分隔的列:#@ 有没有办法找到分隔符之间的数据?我的意思是,例如: #@;Hello #@;World #@;!!! 我必须找到你好,然后是世界!!!。我试过这种方法,但不起作用: tp=${ENDFL##*@#} HELLOSTRING=`printf '"%s"\n' "${tp%%#@;*}"` 有什么想法吗?感谢使用translate命令: echo "#@;Hello #@;World #@;!!!" | tr

我有一个由假脱机创建的文件。此文件包含用分隔符分隔的列:
#@
有没有办法找到分隔符之间的数据?我的意思是,例如:

#@;Hello #@;World #@;!!!
我必须找到你好,然后是世界!!!。我试过这种方法,但不起作用:

tp=${ENDFL##*@#}
          HELLOSTRING=`printf '"%s"\n' "${tp%%#@;*}"`

有什么想法吗?感谢使用translate命令:

  echo "#@;Hello #@;World #@;!!!"  | tr '#@;' '^' | tr -s '^' 
输出:

 Kaizen ~
 $ echo "#@;Hello #@;World #@;!!!"  | tr '#@;' '^' | tr -s '^'
   ^Hello ^World ^!!!
说明:

第一个tr替换“#@”带^的分隔符,但它会执行三次

“#,@,;”是三个独立的文本,因此它分别表示所有三个文本

第二个tr抑制多个^to一的出现

因此,您将得到一个以“^Hello^World^!!”分隔的输出


对于您的文件,只需cat filename,然后通过管道将其传输到translate命令,之后您可以根据需要使用AWK、cut或任何格式或提取。

如果您需要处理大量行

sed -e 's/#@;//g' input.dat
查找分隔符之间的数据(假设变量中有
tp=
建议的值)

如果你想处理这些零件

origIFS=$IFS        # always kep the original $IFS save
IFS='§'            # define a InputFieldSeparator which will not be used in your input
set ${tp//#@;/$IFS} # reduce separator to one char and set $1 ... based on that separator
IFS=$origIFS        # and restore $IFS when you are done
echo "'$1' '$2' '$3' '$4'"  # note that $1 is empty, it is before the first separator)

您可以将
awk
-F
选项一起使用,并使用
$1
等打印适当的值,但您最终要如何处理这些数据?类似于
awk-F'.@;''{print$1}'
?然而,插入。那应该是
awk-F'#;'。什么“插入”?从之前创建的带日期的假脱机插入。现在最重要的是“转换”,如果可能的话,这个
tp=${ENDFL##*}
HELLOSTRING=
printf'%s'\n'${tp%%.*}``在这个您的解决方案中
awk-F''并具有相同的结果。我的方式显示空白的所有字段,我认为这是因为它在第一个分隔符处停止。简单的示例数据(如您所拥有)和该数据所需的输出消除了试图口头描述您的目标时产生的许多问题。请考虑编辑您的问题,以显示需要的输出,与当前的输出。如果不清楚当前输出不正确的原因,那么请注意一些。祝你好运
origIFS=$IFS        # always kep the original $IFS save
IFS='§'            # define a InputFieldSeparator which will not be used in your input
set ${tp//#@;/$IFS} # reduce separator to one char and set $1 ... based on that separator
IFS=$origIFS        # and restore $IFS when you are done
echo "'$1' '$2' '$3' '$4'"  # note that $1 is empty, it is before the first separator)