2007. 11. 3. 20:47 Unix

여러파일 조작하기

여러 파일 조작하기
 
동시에 여러 파일에 대해 조작을 할 필요성을 느낀적이 있는가???
 
여기 그에 대한 해답(솔루션)이 있다.
 
예를 들어, 하나의 파일에 대해서 뿐만 아니라 일련의 파일에 대해서도
(grep을 이용하여) 문자를 찾고, awk 또는 펄스크립트등을 실행하는 등의
여러가지 작업을 수행할 필요가 있다면 unix 프롬프트상에서 다음의
명령어를 사용하라.
 
 $<: foreach i (<file_list>)
 ? echo $i
 ? grep <search_pattern> $i > tmp
 ? awk -f awk_script tmp >> report
 ? ....
 ? ....
 ? end
$<:
 
꺽쇄괄호안의 파일리스트는 다음의 두 종류가 올 수 있다.
 
* 특정한 이름을 지정
 
* 파일 이름의 목록을 포함하는 유닉스 변수. 예를 들면 "p"라는 변수는
다음에 보는 것처럼 "data"라는 문자로 시작하는 모든 파일을 지정할 수
있다.
 
   set p = (data*)
 
다른 예제를 들자면
 
   set g = `grep -l "Startpoint" * `
 
또는
 
   set all = *
(위의 내용은 현재 디렉토리의 모든 파일명을 "all"이라는 변수에 할당한다.
 
그리고 변수명을 "foreach"라는 명령어와 함께 사용한다면 다음과 같이
될 것이다.
 
$<:  foreach i ($all)
  .....
  .....
end
 
-----------------<원문>-------------------
OPERATING ON MULTIPLE FILES
 
Have you ever felt the need to perform a
set of operations on multiple files
simultaneously???
 
Here is a solution for that.
 
For instance, if it is required to perform
multiple operations like searching a string
(using grep), and executing an awk or perl
script etc, etc. on not just one file but a
set of files, use the following commands at
the unix prompt:
 
 $<: foreach i (<file_list>)
 ? echo $i
 ? grep <search_pattern> $i > tmp
 ? awk -f awk_script tmp >> report
 ? ....
 ? ....
 ? end
$<:
 
The files list in the brackets can be either
 
* Specifically mentioned
 
* A unix variable which contains a list of
file names.  For instance, the variable
"p" can be assigned all the files starting
with string "data" as follows:
   set p = (data*)
Other examples are:
   set g = `grep -l "Startpoint" * `
or
   set all = *
(This assigns all file names in the current
directory to the variable "all" )
 
And its usage with the "foreach" command will
be as follows:
 
$<:  foreach i ($all)
  .....
  .....
end
반응형
Posted by She쥐포s

블로그 이미지
She쥐포s
Yesterday
Today
Total

달력

 « |  » 2024.4
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

최근에 올라온 글

최근에 달린 댓글

글 보관함