1

以下のように、 myfile.txtresponsefile.txtという 2 つのファイルがあります。

myfile.txt

user=myname
Was_WAS_AdminId=CN=wsadmin,OU=service,OU=WAS_Secure,OU=tb,ou=dcdc,ou=sysadm,dc=info,dc=prd,dc=dcdc

応答ファイル.txt

'#'Please fill the user id details.
'#'Here is example user=urname.
user=
'#'Please fill the details.
'#'Here is example Was_WAS_AdminId=CN=wsadmin-xxxx.
Was_WAS_AdminId=

ここで、上記の 2 つのファイルを使用すると、一致するパターンを置き換えた後、次の最終結果が得られます。responsefile.txt の内容はそのままで、一致したパターンに myfile.txt で提供される詳細をプレフィックスとして付けるか、最初のパターンが両方のファイルで同じであり、100 以上のパターンになるため、一致する行全体のみを置き換える必要があります。SO、簡単な解決策を提案してください。

responsefile.txt (新しいファイルを置換/パターンで置換)

'#'Please fill the user id details.
'#'Here is example user=urname.
user=myname
'#'Please fill the details.
'#'Here is example Was_WAS_AdminId=CN=wsadmin-xxxx.
Was_WAS_AdminId=CN=wsadmin,OU=service,OU=WAS_Secure,OU=tb,ou=dcdc,ou=sysadm,dc=info,dc=prd,dc=dcdc

パターンは両方のファイルで同じです。たとえば、両方のファイルで " user=" または " Was_WAS_AdminId=" です。

4

2 に答える 2

2

awk ワンライナーは次のとおりです。

$ awk -F= 'NR==FNR{a[$1]=$0;next}$1 in a{$0=a[$1]}1' myfile.txt responsefile.txt 
'#'Please fill the user id details.
'#'Here is example user=urname.
user=myname
'#'Please fill the details.
'#'Here is example Was_WAS_AdminId=CN=wsadmin-xxxx.
Was_WAS_AdminId=CN=wsadmin,OU=service,OU=WAS_Secure,OU=tb,ou=dcdc,ou=sysadm,dc=info,dc=prd,dc=dcdc

コマンド内の 2 つのファイルの順序は重要です

于 2013-08-25T16:16:21.100 に答える