我有这个文件:

# cat pt_Sed.txt
ULNET-PA,broker_etrade,broker_etrade_uk^M,BR    DELIVERTOCOMPID
ULNET-PA,broker_etrade,broker_etrade_uk^M,CO    TARGETSUBID


我想排列线条,使它们看起来像这样:

ULNET-PA,broker_etrade,broker_etrade_uk^M,DELIVERTOCOMPID=BR
ULNET-PA,broker_etrade,broker_etrade_uk^M,TARGETSUBID=CO


我尝试了以下操作,但似乎没有按预期工作:

# x=`awk '{ print $NF }' pt_Sed2.txt`
# echo $x
# DELIVERTOCOMPID
# sed -re "s/\^M,*/&$x=/g" -e 's/ .*//' < pt_Sed.txt
# ULNET-PA,broker_etrade,broker_etrade_uk^M,DELIVERTOCOMPID=BR
# ULNET-PA,broker_etrade,broker_etrade_uk^M,DELIVERTOCOMPID=CO


您能否提出解决方案?
我将不胜感激!

谢谢,
安德烈

最佳答案

$ sed -r 's/,([^[:space:],]+)[[:space:]]+(.*)/,\2=\1/' file
ULNET-PA,broker_etrade,broker_etrade_uk^M,DELIVERTOCOMPID=BR
ULNET-PA,broker_etrade,broker_etrade_uk^M,TARGETSUBID=CO

关于linux - bash脚本问题-将特定单词移至行中的其他位置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19379544/

10-15 05:27