'쉘스크립트'에 해당되는 글 23건
- 2009.03.31 7. sed 란? 2
- 2009.03.05 5. 날짜표시 (date)
- 2009.03.04 4. 기본 루프문 (while)
첫번째 라인 출력
sed -n '1p' filename
마지막 라인 출력
sed -n '$p' filename
두번째 라인 출력
sed -n '2p' filename
첫번째부터 세번째 라인까지 출력 ( 1번 라인 부터 3번 라인까지 포함 )
sed -n '1,3p' filename
첫번째라인 부터 세번째 라인까지 삭제하고 출력
sed '1,3d' filename
특수한 문자열(예를들어 root)을 검색해서 그 라인만 출력
sed -n '/root/p' filename
love가 나오는 행과 peace가 나오는 행 사이의 모든 행들이 출력된다. love가 peace 다음에 나오면 love가 나오는 행부터 마지막 행까지 출력된다.
sed -n ‘/love/,/peace/p’ datafile
파일 안의 빈줄들만 모조리 삭제하고자 할때 .
sed '/^$d' 파일명 > 새파일명
특정 단어를 찾아서 변환하고자 할때
sed 's/TEST/test/g' > 새파일명
특정 단어를 찾아서 지우고자 할때
sed 's/TEST//g' > 새파일명
sed 에 관한 도움말
# sed --help
Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...
suppress automatic printing of pattern space
-e script, --expression=script
add the script to the commands to be executed
-f script-file, --file=script-file
add the contents of script-file to the commands to be executed
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if extension supplied)
-c, --copy
use copy instead of rename when shuffling files in -i mode
(avoids change of input file ownership)
-l N, --line-length=N
specify the desired line-wrap length for the `l' command
--posix
disable all GNU extensions.
-r, --regexp-extended
use extended regular expressions in the script.
-s, --separate
consider files as separate rather than as a single continuous
long stream.
-u, --unbuffered
load minimal amounts of data from the input files and flush
the output buffers more often
--help display this help and exit
--version output version information and exit
'쉘스크립트' 카테고리의 다른 글
14. 지난 파일 압축하고 삭제하기 (2) | 2009.12.18 |
---|---|
13. 파일 비교 스크립트 4 (2) | 2009.11.05 |
12. 파일 개수 비교해서 삭제하는 스크립트 (3) | 2009.10.21 |
11. SSH 접속 차단 스크립트 ( 5번 패스워드 틀리면 자동 차단) (2) | 2009.09.19 |
10. 파일비교 스크립트2 (3) | 2009.09.18 |
9. 여러 파일 하나의 txt 파일로 합치기 스크립트 (3) | 2009.09.10 |
8. 파일 내용 비교1 (3) | 2009.09.10 |
스크립트 문제 (0) | 2009.06.01 |
5. 날짜표시 (date) (0) | 2009.03.05 |
4. 기본 루프문 (while) (0) | 2009.03.04 |
#!/bin/bash
date= date +%Y-%m-%d_%H:%M:%S
echo $date
date= date +%Y-%m-%d_%H:%M:%S
echo $date
이것은 날짜를 표시해주는 스크립트이고
date 명령어를 통해 원하는 방식으로 날짜와 시간등등을 표현해줄 수 있다.
실행시키면 다음과 같은 결과를 얻는다.
[root@localhost ~]# ./date.sh
2009-03-05_15:18:07
2009-03-05_15:18:07
다른 방식으로도 가능하다 today 라는 변수를 지정해서 그 안에 날짜 정보를 넣으면
#!/bin/bash
today=`date +%Y%m%d`
echo $today
today=`date +%Y%m%d`
echo $today
[root@localhost ~]# ./date2.sh
20090305
20090305
이렇게 나오게 된다.
'쉘스크립트' 카테고리의 다른 글
14. 지난 파일 압축하고 삭제하기 (2) | 2009.12.18 |
---|---|
13. 파일 비교 스크립트 4 (2) | 2009.11.05 |
12. 파일 개수 비교해서 삭제하는 스크립트 (3) | 2009.10.21 |
11. SSH 접속 차단 스크립트 ( 5번 패스워드 틀리면 자동 차단) (2) | 2009.09.19 |
10. 파일비교 스크립트2 (3) | 2009.09.18 |
9. 여러 파일 하나의 txt 파일로 합치기 스크립트 (3) | 2009.09.10 |
8. 파일 내용 비교1 (3) | 2009.09.10 |
스크립트 문제 (0) | 2009.06.01 |
7. sed 란? (2) | 2009.03.31 |
4. 기본 루프문 (while) (0) | 2009.03.04 |
#!/bin/bash
A=1
while [ $A -lt 5 ]
do
echo $A
A=`expr $A + 1`
done
A=1
while [ $A -lt 5 ]
do
echo $A
A=`expr $A + 1`
done
이 쉡 스크립트를 보면 While 문을 사용해서
A 를 1부터 차례로 5보다 작은 수 즉 4까지 증가시키면서
화면에 A 값을 출력하는
기본 루프문 이다.
첫줄은 bash 쉡을 이용한다는 뜻
두번째 A=1 은 변수 A 의 초기값이 1 이라는 뜻
세번재 while 문에 조건 즉 변수A ($A) 가 5보다 작을때까지 다음에 오는 do 와 done 사이의 명령을 반복
echo $A 는 화면에 A의 값을 출력
A 에 1씩 더하는 것
무한 루프문
#!/bin/bash
while [ : ]
do
#!/bin/bash
while [ : ]
do
echo -n "test "
done
while [ : ] 에서 : 은 실행결과가 참이므로 do 와 done 사이의 명령을 계속 수행한다.
중지하려면 Ctrl + C 를 눌러 중지한다.
'쉘스크립트' 카테고리의 다른 글
14. 지난 파일 압축하고 삭제하기 (2) | 2009.12.18 |
---|---|
13. 파일 비교 스크립트 4 (2) | 2009.11.05 |
12. 파일 개수 비교해서 삭제하는 스크립트 (3) | 2009.10.21 |
11. SSH 접속 차단 스크립트 ( 5번 패스워드 틀리면 자동 차단) (2) | 2009.09.19 |
10. 파일비교 스크립트2 (3) | 2009.09.18 |
9. 여러 파일 하나의 txt 파일로 합치기 스크립트 (3) | 2009.09.10 |
8. 파일 내용 비교1 (3) | 2009.09.10 |
스크립트 문제 (0) | 2009.06.01 |
7. sed 란? (2) | 2009.03.31 |
5. 날짜표시 (date) (0) | 2009.03.05 |