<kernel>
use_profile 0
use_group 0
file execute /lib64/rc/sh/cgroup-release-agent.sh exec.realpath="/lib64/rc/sh/cgroup-release-agent.sh" exec.argv[0]="/lib64/rc/sh/cgroup-release-agent.sh"
file execute /sbin/init exec.realpath="/sbin/init" exec.argv[0]="/sbin/init"
file execute /sbin/modprobe exec.realpath="/bin/kmod" exec.argv[0]="/sbin/modprobe"
<kernel> /sbin/init
use_profile 0
use_group 0
<kernel> /sbin/init /sbin/openrc
use_profile 0
use_group 0
<kernel> /sbin/init /sbin/openrc /lib64/rc/sh/init-early.sh
use_profile 0
use_group 0
<kernel> /etc/init.d/dmesg
use_profile 0
use_group 0
file execute /lib64/rc/sh/openrc-run.sh exec.realpath="/lib64/rc/sh/openrc-run.sh" exec.argv[0]="/lib64/rc/sh/openrc-run.sh"
file read /etc/rc.conf
file read /run/openrc/depconfig
file read /run/openrc/deptree
file read /sbin/openrc-run
file read proc:/cmdline
file symlink /run/openrc/started/dmesg symlink.target="/etc/init.d/dmesg"
file symlink /run/openrc/starting/dmesg symlink.target="/etc/init.d/dmesg"
file unlink /run/openrc/exclusive/dmesg
file unlink /run/openrc/starting/dmesg
misc env CONFIG_PROTECT
misc env CONFIG_PROTECT_MASK
misc env DCC_EMAILLOG_WHOM_TO_BLAME
misc env DISTCC_ENABLE_DISCREPANCY_EMAIL
misc env DISTCC_FALLBACK
misc env DISTCC_SAVE_TEMPS
misc env DISTCC_SSH
misc env DISTCC_TCP_CORK
misc env DISTCC_VERBOSE
misc env EINFO_LOG
misc env GCC_SPECS
misc env GSETTINGS_BACKEND
misc env GUILE_LOAD_PATH
misc env INFOPATH
misc env LANG
misc env LESS
misc env LESSOPEN
misc env MANPAGER
misc env MANPATH
misc env OPENCL_PROFILE
misc env OPENGL_PROFILE
misc env PATH
misc env QT_GRAPHICSSYSTEM
misc env RC_BOOTLEVEL
misc env RC_DEFAULTLEVEL
misc env RC_LIBEXECDIR
misc env RC_PID
misc env RC_RUNLEVEL
misc env RC_SVCDIR
misc env RC_TMPDIR
misc env RC_UNAME
misc env RC_VERSION
misc env ROOTPATH
misc env TERM
misc env UNCACHED_ERR_FD
misc env VBOX_APP_HOME
misc env XDG_CONFIG_DIRS
misc env XDG_DATA_DIRS
misc env XSESSION
<kernel> /usr/sbin/ntpdate
use_profile 3
use_group 0
misc env LS_COLORS
misc env LANG
misc env DISPLAY
misc env LC_CTYPE
misc env TERM
misc env XAUTHORITY
misc env PATH
misc env COLORTERM
misc env MAIL
misc env LOGNAME
misc env USER
misc env USERNAME
misc env HOME
misc env SHELL
misc env SUDO_COMMAND
misc env SUDO_USER
misc env SUDO_UID
misc env SUDO_GID
network unix dgram send /dev/log
file read /etc/nsswitch.conf
file read /etc/services
file read /etc/host.conf
file read /etc/resolv.conf
file read /etc/hosts
network inet dgram send 127.0.0.1 53
file ioctl socket:[family=2:type=2:protocol=17] 0x541B
file read /etc/gai.conf
network inet dgram bind/send :: 123
network inet dgram bind/send 0.0.0.0 123
<kernel> /sbin/init /sbin/openrc /lib64/rc/sh/init-early.sh /usr/bin/loadkeys
use_profile 0
use_group 0
<kernel> /sbin/init /sbin/openrc /lib64/rc/sh/init.sh
use_profile 0
use_group 0
<kernel> /etc/init.d/ntpd
use_profile 3
use_group 0
misc env LS_COLORS
misc env LANG
misc env DISPLAY
misc env LC_CTYPE
misc env TERM
misc env XAUTHORITY
misc env PATH
misc env COLORTERM
misc env MAIL
misc env LOGNAME
misc env USER
misc env USERNAME
misc env HOME
misc env SHELL
misc env SUDO_COMMAND
misc env SUDO_USER
misc env SUDO_UID
misc env SUDO_GID
file read /sbin/openrc-run
file read /etc/rc.conf
file read proc:/cmdline
file read /etc/profile.env
file read proc:/cpuinfo
file read proc:/1/environ
file read /run/openrc/softlevel
file create /run/openrc/exclusive/ntpd 0664
file write/unlink /run/openrc/exclusive/ntpd
file symlink /run/openrc/starting/ntpd symlink.target="/etc/init.d/ntpd"
file read /run/openrc/depconfig
file read /run/openrc/deptree
file execute /lib64/rc/sh/openrc-run.sh exec.realpath="/lib64/rc/sh/openrc-run.sh" exec.argv[0]="/lib64/rc/sh/openrc-run.sh"
misc env CONFIG_PROTECT
misc env CONFIG_PROTECT_MASK
misc env GCC_SPECS
misc env GSETTINGS_BACKEND
misc env INFOPATH
misc env LESS
misc env LESSOPEN
misc env MANPAGER
misc env MANPATH
misc env OPENGL_PROFILE
misc env QT_GRAPHICSSYSTEM
misc env ROOTPATH
misc env VBOX_APP_HOME
misc env XDG_CONFIG_DIRS
misc env XDG_DATA_DIRS
misc env RC_VERSION
misc env RC_LIBEXECDIR
misc env RC_SVCDIR
misc env RC_TMPDIR
misc env RC_BOOTLEVEL
misc env RC_RUNLEVEL
misc env RC_DEFAULTLEVEL
misc env RC_UNAME
misc env EINFO_LOG
misc env RC_SVCNAME
misc env RC_OPENRC_PID
misc env RC_RUNSCRIPT_PID
misc env RC_CMD
file read /bin/bash
file read/write /dev/tty
file read /usr/lib64/locale/locale-archive
file read /etc/nsswitch.conf
file read /etc/passwd
file ioctl devpts:/3 0x540F
file read /lib64/rc/sh/openrc-run.sh
file read /lib64/rc/sh/functions.sh
file execute /lib64/rc/bin/eval_ecolors exec.realpath="/lib64/rc/bin/eval_ecolors" exec.argv[0]="eval_ecolors"
misc env PWD
misc env SHLVL
misc env _
file read /usr/share/terminfo/r/rxvt-unicode-256color
file ioctl devpts:/3 0x5413
file read /lib64/rc/sh/rc-functions.sh
file read /lib64/rc/sh/rc-cgroup.sh
file read /etc/conf.d/ntpd
file read /lib64/rc/sh/runit.sh
file read /lib64/rc/sh/s6.sh
file read /lib64/rc/sh/start-stop-daemon.sh
file read /lib64/rc/sh/supervise-daemon.sh
file write/truncate /sys/fs/cgroup/cpu/tasks
file write/truncate /sys/fs/cgroup/cpuacct/tasks
file write/truncate /sys/fs/cgroup/cpuset/tasks
file write/truncate /sys/fs/cgroup/freezer/tasks
file write/truncate /sys/fs/cgroup/memory/tasks
file write/truncate /sys/fs/cgroup/openrc/tasks
file execute /bin/mkdir exec.realpath="/bin/mkdir" exec.argv[0]="mkdir"
misc env RC_SERVICE
misc env SVCNAME
file mkdir /sys/fs/cgroup/openrc/ntpd/ 0700
file write/truncate /sys/fs/cgroup/openrc/ntpd/tasks
file read /etc/init.d/ntpd
file execute /lib64/rc/bin/ebegin exec.realpath="/lib64/rc/bin/ebegin" exec.argv[0]="ebegin"
file execute /sbin/start-stop-daemon exec.realpath="/sbin/start-stop-daemon" exec.argv[0]="start-stop-daemon"
file read/write /dev/null
file ioctl /dev/tty 0x5422
file execute /usr/sbin/ntpd exec.realpath="/usr/sbin/ntpd" exec.argv[0]="/usr/sbin/ntpd"
file read /usr/lib64/gcc/x86_64-pc-linux-gnu/6.3.0/libgcc_s.so.1
network unix dgram send /dev/log
file mkdir /run/openrc/daemons/ntpd/ 0755
file create /run/openrc/daemons/ntpd/001 0666
file read/write/unlink /run/openrc/daemons/ntpd/001
file execute /lib64/rc/bin/eend exec.realpath="/lib64/rc/bin/eend" exec.argv[0]="eend"
file execute /lib64/rc/bin/service_set_value exec.realpath="/lib64/rc/bin/service_set_value" exec.argv[0]="service_set_value"
file read /etc/services
file read /etc/host.conf
file read /etc/resolv.conf
file read /etc/hosts
file create /run/ntpd.pid 0666
file read/write/unlink /run/ntpd.pid
file mkdir /run/openrc/options/ntpd/ 0755
file read /etc/ntp.conf
file create /run/openrc/options/ntpd/command 0666
file read/write/unlink /run/openrc/options/ntpd/command
file ioctl socket:[family=1:type=2:protocol=0] 0x8933
file create /run/openrc/options/ntpd/pidfile 0666
file read/write/unlink /run/openrc/options/ntpd/pidfile
file symlink /run/openrc/started/ntpd symlink.target="/etc/init.d/ntpd"
file unlink /run/openrc/starting/ntpd
file symlink /run/openrc/stopping/ntpd symlink.target="/etc/init.d/ntpd"
file unlink /run/openrc/started/ntpd
file execute /lib64/rc/bin/service_get_value exec.realpath="/lib64/rc/bin/service_get_value" exec.argv[0]="service_get_value"
file unlink /run/openrc/stopping/ntpd
file rmdir /run/openrc/options/ntpd/
file rmdir /run/openrc/daemons/ntpd/
network inet dgram bind/send @ALLIPV6 123
network inet dgram bind/send @ALLIPV4 123
file ioctl socket:[family=2:type=2:protocol=17] 0x541B
file read /etc/gai.conf
network inet dgram send 127.0.0.1 53
misc env *
misc env \*
file ioctl /dev/console 0x540F
file ioctl /dev/console 0x5413
file mkdir /sys/fs/cgroup/openrc/ntpd/ 0755
file read/write /dev/console
file read /etc/terminfo/l/linux
bash 스크립트나 Linux 시스템에서 실행할 수 있는 모든 종류의 스크립트를 사용하여 use_profile 0 및 use_group 0이 포함된 모든 프로필을 삭제해야 합니다. awk, grep, sed를 시도했지만 아무런 진전이 없었습니다.
위의 내용을 아래의 내용으로 바꿔야 합니다. 어떤 도구를 사용해야 하는지에 대한 팁이나 제안, 사용 방법을 알려주시면 매우 감사하겠습니다.
<kernel> /usr/sbin/ntpdate
use_profile 3
use_group 0
misc env LS_COLORS
misc env LANG
misc env DISPLAY
misc env LC_CTYPE
misc env TERM
misc env XAUTHORITY
misc env PATH
misc env COLORTERM
misc env MAIL
misc env LOGNAME
misc env USER
misc env USERNAME
misc env HOME
misc env SHELL
misc env SUDO_COMMAND
misc env SUDO_USER
misc env SUDO_UID
misc env SUDO_GID
network unix dgram send /dev/log
file read /etc/nsswitch.conf
file read /etc/services
file read /etc/host.conf
file read /etc/resolv.conf
file read /etc/hosts
network inet dgram send 127.0.0.1 53
file ioctl socket:[family=2:type=2:protocol=17] 0x541B
file read /etc/gai.conf
network inet dgram bind/send :: 123
network inet dgram bind/send 0.0.0.0 123
<kernel> /etc/init.d/ntpd
use_profile 3
use_group 0
misc env LS_COLORS
misc env LANG
misc env DISPLAY
misc env LC_CTYPE
misc env TERM
misc env XAUTHORITY
misc env PATH
misc env COLORTERM
misc env MAIL
misc env LOGNAME
misc env USER
misc env USERNAME
misc env HOME
misc env SHELL
misc env SUDO_COMMAND
misc env SUDO_USER
misc env SUDO_UID
misc env SUDO_GID
file read /sbin/openrc-run
file read /etc/rc.conf
file read proc:/cmdline
file read /etc/profile.env
file read proc:/cpuinfo
file read proc:/1/environ
file read /run/openrc/softlevel
file create /run/openrc/exclusive/ntpd 0664
file write/unlink /run/openrc/exclusive/ntpd
file symlink /run/openrc/starting/ntpd symlink.target="/etc/init.d/ntpd"
file read /run/openrc/depconfig
file read /run/openrc/deptree
file execute /lib64/rc/sh/openrc-run.sh exec.realpath="/lib64/rc/sh/openrc-run.sh" exec.argv[0]="/lib64/rc/sh/openrc-run.sh"
misc env CONFIG_PROTECT
misc env CONFIG_PROTECT_MASK
misc env GCC_SPECS
misc env GSETTINGS_BACKEND
misc env INFOPATH
misc env LESS
misc env LESSOPEN
misc env MANPAGER
misc env MANPATH
misc env OPENGL_PROFILE
misc env QT_GRAPHICSSYSTEM
misc env ROOTPATH
misc env VBOX_APP_HOME
misc env XDG_CONFIG_DIRS
misc env XDG_DATA_DIRS
misc env RC_VERSION
misc env RC_LIBEXECDIR
misc env RC_SVCDIR
misc env RC_TMPDIR
misc env RC_BOOTLEVEL
misc env RC_RUNLEVEL
misc env RC_DEFAULTLEVEL
misc env RC_UNAME
misc env EINFO_LOG
misc env RC_SVCNAME
misc env RC_OPENRC_PID
misc env RC_RUNSCRIPT_PID
misc env RC_CMD
file read /bin/bash
file read/write /dev/tty
file read /usr/lib64/locale/locale-archive
file read /etc/nsswitch.conf
file read /etc/passwd
file ioctl devpts:/3 0x540F
file read /lib64/rc/sh/openrc-run.sh
file read /lib64/rc/sh/functions.sh
file execute /lib64/rc/bin/eval_ecolors exec.realpath="/lib64/rc/bin/eval_ecolors" exec.argv[0]="eval_ecolors"
misc env PWD
misc env SHLVL
misc env _
file read /usr/share/terminfo/r/rxvt-unicode-256color
file ioctl devpts:/3 0x5413
file read /lib64/rc/sh/rc-functions.sh
file read /lib64/rc/sh/rc-cgroup.sh
file read /etc/conf.d/ntpd
file read /lib64/rc/sh/runit.sh
file read /lib64/rc/sh/s6.sh
file read /lib64/rc/sh/start-stop-daemon.sh
file read /lib64/rc/sh/supervise-daemon.sh
file write/truncate /sys/fs/cgroup/cpu/tasks
file write/truncate /sys/fs/cgroup/cpuacct/tasks
file write/truncate /sys/fs/cgroup/cpuset/tasks
file write/truncate /sys/fs/cgroup/freezer/tasks
file write/truncate /sys/fs/cgroup/memory/tasks
file write/truncate /sys/fs/cgroup/openrc/tasks
file execute /bin/mkdir exec.realpath="/bin/mkdir" exec.argv[0]="mkdir"
misc env RC_SERVICE
misc env SVCNAME
file mkdir /sys/fs/cgroup/openrc/ntpd/ 0700
file write/truncate /sys/fs/cgroup/openrc/ntpd/tasks
file read /etc/init.d/ntpd
file execute /lib64/rc/bin/ebegin exec.realpath="/lib64/rc/bin/ebegin" exec.argv[0]="ebegin"
file execute /sbin/start-stop-daemon exec.realpath="/sbin/start-stop-daemon" exec.argv[0]="start-stop-daemon"
file read/write /dev/null
file ioctl /dev/tty 0x5422
file execute /usr/sbin/ntpd exec.realpath="/usr/sbin/ntpd" exec.argv[0]="/usr/sbin/ntpd"
file read /usr/lib64/gcc/x86_64-pc-linux-gnu/6.3.0/libgcc_s.so.1
network unix dgram send /dev/log
file mkdir /run/openrc/daemons/ntpd/ 0755
file create /run/openrc/daemons/ntpd/001 0666
file read/write/unlink /run/openrc/daemons/ntpd/001
file execute /lib64/rc/bin/eend exec.realpath="/lib64/rc/bin/eend" exec.argv[0]="eend"
file execute /lib64/rc/bin/service_set_value exec.realpath="/lib64/rc/bin/service_set_value" exec.argv[0]="service_set_value"
file read /etc/services
file read /etc/host.conf
file read /etc/resolv.conf
file read /etc/hosts
file create /run/ntpd.pid 0666
file read/write/unlink /run/ntpd.pid
file mkdir /run/openrc/options/ntpd/ 0755
file read /etc/ntp.conf
file create /run/openrc/options/ntpd/command 0666
file read/write/unlink /run/openrc/options/ntpd/command
file ioctl socket:[family=1:type=2:protocol=0] 0x8933
file create /run/openrc/options/ntpd/pidfile 0666
file read/write/unlink /run/openrc/options/ntpd/pidfile
file symlink /run/openrc/started/ntpd symlink.target="/etc/init.d/ntpd"
file unlink /run/openrc/starting/ntpd
file symlink /run/openrc/stopping/ntpd symlink.target="/etc/init.d/ntpd"
file unlink /run/openrc/started/ntpd
file execute /lib64/rc/bin/service_get_value exec.realpath="/lib64/rc/bin/service_get_value" exec.argv[0]="service_get_value"
file unlink /run/openrc/stopping/ntpd
file rmdir /run/openrc/options/ntpd/
file rmdir /run/openrc/daemons/ntpd/
network inet dgram bind/send @ALLIPV6 123
network inet dgram bind/send @ALLIPV4 123
file ioctl socket:[family=2:type=2:protocol=17] 0x541B
file read /etc/gai.conf
network inet dgram send 127.0.0.1 53
misc env *
misc env \*
file ioctl /dev/console 0x540F
file ioctl /dev/console 0x5413
file mkdir /sys/fs/cgroup/openrc/ntpd/ 0755
file read/write /dev/console
file read /etc/terminfo/l/linux
답변1
귀하의 질문은 다음과 매우 유사합니다패턴 일치를 기반으로 파일의 전체 단락을 인쇄합니다.귀하의 경우에는 텍스트 부분으로 구분되어 <kernel>...
있으며 그 반대를 원합니다(즉, 일치하는 부분 제거). 이러한 솔루션을 필요에 맞게 조정할 수 있습니다.그리고sed
:
sed '/<kernel>/!{H;$!d;};x;/\nuse_profile 0\nuse_group 0\n/d' infile
또는 sed
구문이 마음에 들지 않는 경우:
sed -e '/<kernel>/!{H;$!d' -e '}' -e 'x;/\nuse_profile 0\nuse_group 0\n/d' infile
답변2
앗방법:
awk 'BEGIN{fn="use_profile_output";}/<kernel>/{getline up; if(up~/use_profile [1-9][0-9]*/)
{f=1; print $0 RS up > fn; next }else{ f=0 }}{ if(f) print > fn; }' file
fn="use_profile_output"
- fn(파일 이름) 변수에는 use_profile_output
0을 포함하지 않는 모든 블록으로 <kernel>
결과 파일 이름이 포함됩니다.use_profile
0
/<kernel>/
- 키워드가 포함된 줄을 만날 때마다 <kernel>
다음 중괄호 그룹이 실행됩니다.
getline up;
- 키워드가 포함된 다음 레코드를 가져와 use_profile
변수에 할당up
use_profile_output
파일 내용(간단한 출력을 표시하기 위해 일부 줄이 생략됨):
<kernel> /usr/sbin/ntpdate
use_profile 3
use_group 0
misc env LS_COLORS
misc env LANG
misc env DISPLAY
misc env LC_CTYPE
...
...
network inet dgram bind/send :: 123
network inet dgram bind/send 0.0.0.0 123
<kernel> /etc/init.d/ntpd
use_profile 3
use_group 0
misc env LS_COLORS
misc env LANG
...
...
misc env *
misc env \*
file ioctl /dev/console 0x540F
file ioctl /dev/console 0x5413
file mkdir /sys/fs/cgroup/openrc/ntpd/ 0755
file read/write /dev/console
file read /etc/terminfo/l/linux