EXPORTER_JAR_PATH
이것은 파일 끝까지 " "를 포함하는 줄에서 모든 줄을 삭제하려는 파일입니다.
more ambari-agent.ini
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific
export EXPORTER_JAR_PATH=/tmp/hgt.yml
[server]
hostname=master.sys65.com
url_port=8440
secured_url_port=8441
connect_retry_delay=10
max_reconnect_retry_delay=30
EXPORTER_JAR_PATH
이것은 끝까지 포함된 줄을 삭제하는 내 솔루션입니다.
sed '1,/EXPORTER_JAR_PATH/!d' ambari-agent.ini
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific
export EXPORTER_JAR_PATH=/tmp/hgt.yml
우리가 라인을 볼 수 있듯이 -Export
EXPORTER_JAR_PATH=/tmp/hgt.yml
아직도 존재하는데, 어디가 잘못된 걸까요?
예상 출력
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific
답변1
sed '/EXPORTER_JAR_PATH/,$d' file
이렇게 하면 하위 문자열이 포함된 첫 번째 줄부터 EXPORTER_JAR_PATH
파일 끝까지( $
파일 끝 주소 지정) 모든 줄이 삭제됩니다.
명령이 수행하는 작업은 라인 1과 해당 문자열을 포함하는 라인 사이의 범위에 속하지 않는 모든 라인을 삭제하는 것입니다. 이는 하위 문자열을 포함하는 줄이 EXPORTER_JAR_PATH
삭제되지 않음을 의미합니다.
또는 Paul_Pendant와 mosvy가 아래 의견에서 지적한 것처럼,
sed -n '/EXPORTER_JAR_PATH/q;p' file
를 사용하면 스크립트가 종료되는 줄에 p
도달할 때까지 각 줄을 명시적으로 인쇄합니다 . 일반 기본 출력을 비활성화하는 옵션 EXPORTER_JAR_PATH
으로 인해 문자열이 있는 줄이 인쇄되지 않습니다 . -n
이것의 이점은 sed
전체 파일을 읽을 필요가 없다는 것입니다(그러나 파일이 너무 짧기 때문에 이 특정한 경우에는 큰 차이를 만들지 않습니다).
awk
읽을 것과 동등한 것
awk '/EXPORTER_JAR_PATH/ { exit } { print }' file
또는 더 짧게,
awk '/EXPORTER_JAR_PATH/ { exit }; 1' file