ファイル内の文字列から単語を削除しようとしています。問題は、この単語がファイル内にさらに存在することです。AWK inside SEDの使い方
私は私がやっているように、ファイルからホスト名を削除する必要があります。
less /etc/dhcp/dhclient.conf | grep host-name
を、これは私が取得していますものです:だから
send host-name = gethostname();
domain-name, domain-name-servers, domain-search, host-name,
# option host-name "andare.swiftmedia.com";
は、今私はAWKを使用してみました:
less /etc/dhcp/dhclient.conf | grep host-name | awk 'NR>1 {print $4}'
host-name,
"andare.swiftmedia.com";
しかし、私はどのように特定のオカレンス上のファイルからこれを削除することはできません(2番目のオカレンスで)
sedとawkの両方が常に私を混乱させます:/ あなたの助けに感謝します。
EDIT: 現在/etc/dhcp/dhclient.conf
# Configuration file for /sbin/dhclient.
#
# This is a sample configuration file for dhclient. See dhclient.conf's
# man page for more information about the syntax of this file
# and a more comprehensive list of the parameters understood by
# dhclient.
#
# Normally, if the DHCP server provides reasonable information and does
# not leave anything out (like the domain name, for example), then
# few changes must be made to this file, if any.
#
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
send host-name = gethostname();
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, domain-search, host-name,
dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers,
netbios-name-servers, netbios-scope, interface-mtu,
rfc3442-classless-static-routes, ntp-servers;
私がリクエストから始まる行からホスト名を削除する必要があります。
予想:
# Configuration file for /sbin/dhclient.
#
# This is a sample configuration file for dhclient. See dhclient.conf's
# man page for more information about the syntax of this file
# and a more comprehensive list of the parameters understood by
# dhclient.
#
# Normally, if the DHCP server provides reasonable information and does
# not leave anything out (like the domain name, for example), then
# few changes must be made to this file, if any.
#
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
send host-name = gethostname();
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, domain-search,
dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers,
netbios-name-servers, netbios-scope, interface-mtu,
rfc3442-classless-static-routes, ntp-servers;
よろしく
期待される出力はどのように見えますか?適切なサンプルと期待される出力で明確に更新できますか? – Inian
現在の出力と期待される出力で編集されました – LukeJ
'sed'コマンドで削除されるテキストとして' host-name'ではなく 'host-name'を単にテキストとして使用してみませんか? – Sundeep