리눅스 a.txt의 목록들을 b. txt에서 지우고 싶습니다.

gkns401의 이미지

취약점 진단을 자동화 툴로 만들어 보려고 합니다.

주요정보통신기반시설 기술적 취약점 분석 평가 방법 상세가이드의 u-24 항목입니다.

24_s.txt 의 내용들 중 24_1.txt에 있는 목록들(파일명)을 지우고 싶은데

목록 하나만 지워지고 나머지는 지워지지 않는군요 ;;

참고로 지우는것은 끝에 마지막 필드 (9번째 필드) 입니다.

ls -l 을 했을 시 나오는 파일명 입니다.

24_1.txt 의 내용은 이렇습니다.


/sbin/dump
/usr/bin/lpq-lpd
/usr/bin/newgrp
/sbin/restore
/usr/bin/lpr
/usr/sbin/lpc
/sbin/unix_chkpwd
/usr/bin/lpr-lpd
/usr/sbin/lpc-lpd
/usr/bin/at
/usr/bin/lprm
/usr/sbin/traceroute
/usr/bin/lpq
/usr/bin/lprm-lpd

24_s.txt 의 내용은

find / -user root -type f \( -perm -04000 -o -perm -02000 \) -xdev -exec ls -al {} \;

의 출력을 저장한 겁니다.

#! /bin/bash 
 
###touch 24.txt
### in advance  make the 24.txt contained file list
touch 24_1.txt
touch 24_s.txt
cat 24.txt >24_1.txt
 
cat 24_1.txt
 
find / -user root -type f \( -perm -04000 -o -perm -02000 \) -xdev -exec ls -al {} \; > 24_s.txt
del=$(sed -n '1p' 24_1.txt)
i=0
 
 
while [ "$del" != "" ]
do
 
	sed -i "s|$del||" 24_s.txt
	sed -i '1d' 24_1.txt
	del=$(sed -n '1p' 24_1.txt)
	sed -n "$ip" 24_s.txt
 
 
done

문법 에러는 없습니다. 운영체제는 cent os 구요

수동으로 하나하나 입력 했을때는 잘 됩니다..

그래서 더 의문입니다.

현명하신분들의 답변 기다립니다.

..

익명 사용자의 이미지

(rm 24_s.txt; join -v2 <(sort 24_1.txt) - > 24_s.txt) < <(sort 24_s.txt)

gkns401의 이미지

제가 공백 처리를 제대로 못해서였군요 ..;; 글 삭제해야 할거 같은데 방법 아시나요 ?

세벌의 이미지

글 지우려면 관리자에게 요청해야 됩니다. 그런데 지울 까닭이 있나요?
글 지우지 마세요. 비슷한 문제를 겪는 다른 분이 도움을 받을 수 있도록.

gkns401의 이미지

제가 쓴글이 괜히 쓸데 없이 용량만 차지하는게 아닐까 싶어
지우려고 했는데 다른분에게 도움 줄 수 있다면 남겨두는 것도 좋겠네요 ~
관리자에게 요청해야 지울 수 있다는 사실을 처음 알았네요
글을 신중하게 쓸 필요가 있겠어요

익명 사용자의 이미지

(rm 24_s.txt; join -11 -29 -v2 -o 2.{1..9} <(sort 24_1.txt) - > 24_s.txt) < <(sort 24_s.txt)

gkns401의 이미지

24_1.txt 의 파일 목록들 끝에 공백 즉 띄워쓰기가 있어서 인식이 제대로 안되는 겁니다.
host os 의 메모장에서 복사해서 그런지 공백이 들어가 있더군요, 복사해서 내용 넣을 때 특히나 쉘 스크립트에서는
공백 주의 해야겠군요

bushi의 이미지

[schoi0@SEL-SCHOI0-D2 build]$ cat 24.txt 
/1/2/3
 
/1/3
 
/1/2/4
[schoi0@SEL-SCHOI0-D2 build]$ cat 24_s.txt 
/1/4
/1/2/3
/1/3/2
/1/3
/1/2/4
[schoi0@SEL-SCHOI0-D2 build]$ grep -vxFf 24.txt 24_s.txt 
/1/4
/1/3/2
gkns401의 이미지

압축, 압축 해제 할때 본 옵션 같은데 아주 간단한 방법이군요

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.