2019. 9. 9. 15:45ㆍ컴퓨터_Com/컴퓨터_Com
좋은 참조 링크: https://recipes4dev.tistory.com/171
GNU AWK User's Guide: https://www.gnu.org/software/gawk/manual/gawk.html#Nonconstant-Fields
1. a.out 파일의 일부분 자르고, 빈 줄 없애기
1
2
3
4
5
|
# 먼저, "a.out" 파일에서 ' S u m m a r y'로 시작하는 줄 부터 '1S'로 시작하는 줄까지를 잘라내고
# '|'로
# 다음으로 ' '(공백)이 처음(^)부터 끝($)까지 있는 줄, 즉 빈줄을 없애는 명령임.
awk '/^ S u m m a r y/,/^1S/' a.out |sed '/^ *$/d'
|
cs |
2. a.out 파일에서 'PIN.EDT PPIN' 문자가 포함된 줄만 출력하되 첫 번째에 해당하는 줄만 출력하려면
'grep -m NUM' 옵션을 쓰면 NUM에 해당하는 개수만 뽑을 수 있다.
'grep -A NUM' 옵션을 쓰면 매치되는 줄 아래로 NUM에 해당하는 줄을 추가로 뽑을 수 있다. 이때 첫 번째 output과 두 번째 output사이에는 '--'가 출력된다.
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
31
32
33
34
|
grep -m 2 "PIN.EDT PPIN" a.out
PIN.EDT PPIN - Peak Pin Power: Plane of Peak
PIN.EDT PPIN - Peak Pin Power: Plane of Peak
grep -m 2 -A 11 "PIN.EDT PPIN" a.out
<<< 출력 >>>
PIN.EDT PPIN - Peak Pin Power: Plane of Peak
Renorm = 1.00000E+00 Axial Plane = 12
** 9 10 11 12 13 14 15 16 17 **
9 0.785 1.098 1.290 1.147 1.051 1.227 1.429 0.915 0.479 09
10 1.098 1.338 1.152 1.447 1.252 1.424 1.282 1.406 0.573 10
11 1.290 1.150 1.197 1.288 1.560 1.379 1.455 1.257 0.561 11
12 1.147 1.439 1.286 1.553 1.311 1.471 1.341 1.502 0.516 12
13 1.051 1.244 1.556 1.312 1.425 1.258 1.480 0.842 13
14 1.227 1.421 1.379 1.471 1.262 1.160 1.450 0.558 14
15 1.429 1.287 1.456 1.343 1.482 1.451 0.751 15
16 0.915 1.405 1.258 1.504 0.843 0.557 16
17 0.479 0.572 0.562 0.517 17
--
PIN.EDT PPIN - Peak Pin Power: Plane of Peak
Renorm = 1.00000E+00 Axial Plane = 12
** 9 10 11 12 13 14 15 16 17 **
9 0.784 1.097 1.289 1.146 1.052 1.228 1.429 0.917 0.479 09
10 1.097 1.336 1.151 1.446 1.252 1.424 1.284 1.407 0.574 10
11 1.289 1.149 1.197 1.287 1.559 1.381 1.456 1.259 0.562 11
12 1.146 1.438 1.285 1.551 1.310 1.471 1.343 1.503 0.517 12
13 1.052 1.244 1.554 1.311 1.423 1.258 1.479 0.843 13
14 1.228 1.421 1.381 1.471 1.262 1.160 1.449 0.558 14
15 1.429 1.289 1.457 1.345 1.480 1.450 0.752 15
16 0.917 1.406 1.260 1.504 0.844 0.557 16
17 0.479 0.573 0.563 0.518 17 17
|
cs |
3. a.out 파일에서 'PIN.EDT PPIN' 문자가 포함된 줄만 출력하되 마지막 부분만 뽑고 싶으면
'tail -n NUM' 옵션을 쓴다. 이 옵션을 쓰면 끝에서부터 NUM번째 줄까지 뽑을 수 있다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
grep -A 10 ' PRI.STA 2KIN' a.out | tail -n 11
<<< 출력 >>>
PRI.STA 2KIN - Assembly 2D Ave KINF - K-infinity
** 9 10 11 12 13 14 15 16 17 **
9 0.878 0.965 1.096 0.958 0.926 0.963 1.101 0.949 0.941 09
10 0.965 1.103 0.956 1.098 0.958 1.092 0.985 1.143 0.980 10
11 1.096 0.957 0.961 0.952 1.087 0.950 1.095 1.042 0.963 11
12 0.958 1.099 0.952 1.088 0.948 1.087 1.004 1.168 0.949 12
13 0.926 0.959 1.087 0.948 1.089 0.977 1.125 0.932 13
14 0.963 1.092 0.951 1.087 0.977 0.973 1.175 0.941 14
15 1.101 0.987 1.095 1.004 1.125 1.175 0.945 15
16 0.949 1.144 1.042 1.168 0.932 0.940 16
17 0.941 0.981 0.964 0.949 17
|
cs |
4. grep으로 여러 단어를 뽑거나 빼고 싶으면 아래와 같이 해라.
'grep -E 'xxx1|xxx2|xxx3' 또는 'grep -Ev 'xxx1|xxx2|xxx3'
'grep -E "xxx1\|xxx2\|xxx3"는 이중에서 하나라고 들어 있으면 뽑는다.
'grep -e pattern1 -e pattern2'는 or의 개념이다.
'grep -E -A4 '5 \(K \, 2 \)|30 \(P \, 10\)' aaa.out
5. 2개의 파일을 가로로 합치고 싶을 때
'paste edit1.dat edit2.dat > edit.sum'
6. cut으로 자르기 (grep, awk, cut, uniq 수행)
'grep _UPGRADE_FRAMEWORK_ *.[ch] | awk '{print $1}' | cut -d ':' -f1 | uniq'
[문자열 자르기] awk, cut을 이용
기존에 #ifdef로 이력을 남겼던 것을 찾아서 삭제하는 작업을 하고 있다. 해당 파일을 grep으로 찾아서 열어보고 처리해야 하는데 번거롭다. 파일명만 가져다가 한번에 사용하고 싶어서 문자열 자�
sfixer.tistory.com
7. cut string
https://stackabuse.com/substrings-in-bash/
Substrings in Bash
Throughout your programming career you'll find that there are quite a few times you need to extract a substring from another string. Strings are one of the most common data structures, so this comes up often. I bet you could tell me how to do it in your fa
stackabuse.com
8. sed로 삭제하기
https://www.theunixschool.com/2012/06/sed-25-examples-to-delete-line-or.html
sed - 25 examples to delete a line or pattern in a file
In this article of sed tutorial series , we are going to see how to delete or remove a particular line or a particular pattern from a file...
www.theunixschool.com
9. sed로 replace(변경)
sed -i 's/old-text/new-text/g' input.txt
https://www.cyberciti.biz/faq/how-to-use-sed-to-find-and-replace-text-in-files-in-linux-unix-shell/
How to use sed to find and replace text in files in Linux / Unix shell
sed find and replace text command: This guide explains how to use sed to find and replace text within a file on a Linux, macOS, *BSD and Unix
www.cyberciti.biz
10. grep 위 아래로 22줄 출력
grep -A 22 or -B 22
https://eat-hokey.tistory.com/7
grep 시 윗줄, 아래줄 내용 같이 출력하기
grep 시 윗줄, 아래줄 내용 같이 출력하기 linux에서 grep을 사용하여 로그를 검색하다보면 검색 특정문자열의 바로 윗줄, 아래줄을 보고 싶을 때가 있다. grep의 옵션 중 A, B 옵션으로 해결 가능하다.
eat-hokey.tistory.com
'컴퓨터_Com > 컴퓨터_Com' 카테고리의 다른 글
노션 단축키 (0) | 2023.11.17 |
---|---|
파일 개수 세기 (0) | 2022.06.03 |
awk 사용하기 (0) | 2021.02.09 |
Shell Script (0) | 2020.05.08 |
CSV 파일 합치기 (0) | 2019.11.07 |