質問

I want to replace IP address after second comma to 92.2.11.1 for all:

pr,th-klmndisj,92.2.11.1
da,th-kl532disj,92.2.11.8
fr,th-klmn4532j,92.2.21.2
pr,th-klmn52sj,92.2.11.3

Expected View:

pr,th-klmndisj,92.2.11.1
da,th-kl532disj,92.2.11.1
fr,th-klmn4532j,92.2.11.1
pr,th-klmn52sj,92.2.11.1
役に立ちましたか?

解決

You probably meant the second comma.

sed 's/^\([^,]*,[^,]*,\).*/\192.2.11.1/'

Explanation: Search for non-commas, a comma, more non-commas, a coma. The part in \(...\) is replaced by itself (\1), the rest of the line is thrown out and the new string is printed.

他のヒント

sed 's/,[^,]*$/,92.2.11.1/g' file

test

kent$  echo "pr,th-klmndisj,92.2.11.1
dquote> da,th-kl532disj,92.2.11.8
dquote> fr,th-klmn4532j,92.2.21.2
dquote> pr,th-klmn52sj,92.2.11.3"|sed 's/,[^,]*$/,92.2.11.1/g'
pr,th-klmndisj,92.2.11.1
da,th-kl532disj,92.2.11.1
fr,th-klmn4532j,92.2.11.1
pr,th-klmn52sj,92.2.11.1
awk -F, '$3="92.2.11.1"' OFS=, file
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top