Linux2019. 9. 2. 19:06

특정필드를 날릴려면 미리 다른데 저장을 하고 =""으로 지정하면 되겠네?

 

$ awk '/Aaron/{ first_name=$2 ; second_name=$3 ; print first_name, second_name ; }' names.txt

[랑크 : https://www.tecmint.com/learn-awk-variables-numeric-expressions-and-assignment-operators/]

'Linux' 카테고리의 다른 글

csv에서는 awk 보단 cut  (0) 2019.09.05
awk csv  (0) 2019.09.05
awk 치환(삭제)  (0) 2019.09.02
tail과 cat 합치기  (0) 2019.09.02
awk 구분자 탭으로 인식시키기  (0) 2019.09.02
Posted by 구차니
Linux2019. 9. 2. 19:05

항상 그렇지만...

삭제는 ""으로 치환하는거고 그 함수로 sub와 gsub를 지원하는 듯

 

sub

cat my_list.txt | awk -F '\t' -v OFS='\t' '{ sub("-",".",$3); print }'

[링크 : http://bahndal.egloos.com/565881]

 

gsub

awk -F\, '{gsub(/[ \t]+$/, "", $2); print $2 ":"}'

[링크 : https://stackoverflow.com/questions/9985528/how-can-i-trim-white-space-from-a-variable-in-awk]

 

sub는 처음 매칭되는 것만 치환, gsub는 전역 치환인듯

sub(r, s [, t])

Just like gsub(), but only the first matching substring is replaced.

gsub(r, s [, t])

For each substring matching the regular expression r in the string t, substitute the string s, and return the number of substitutions. If t is not supplied, use $0. An & in the replacement text is replaced with the text that was actually matched. Use \& to get a literal &. (This must be typed as "\\&"; see GAWK: Effective AWK Programming for a fuller discussion of the rules for &'s and backslashes in the replacement text of sub(), gsub(), and gensub().)

[링크 : https://linux.die.net/man/1/awk]

'Linux' 카테고리의 다른 글

awk csv  (0) 2019.09.05
awk 변수 지정  (0) 2019.09.02
tail과 cat 합치기  (0) 2019.09.02
awk 구분자 탭으로 인식시키기  (0) 2019.09.02
awk 특정 열 제외하기  (0) 2019.09.02
Posted by 구차니
Linux2019. 9. 2. 17:51

명령행으로 묶은 다음 그걸 전체로 리다이렉션 하면 되는 구나..

 

{ tail --lines=+7 text1; cat text2; } > out_put 

[링크 : https://stackoverflow.com/questions/20499969/combining-cat-and-tail]

'Linux' 카테고리의 다른 글

awk 변수 지정  (0) 2019.09.02
awk 치환(삭제)  (0) 2019.09.02
awk 구분자 탭으로 인식시키기  (0) 2019.09.02
awk 특정 열 제외하기  (0) 2019.09.02
linux 수동 trim  (0) 2019.08.16
Posted by 구차니

\! pwd

 

그냥 외부 명령어 실행해서 확인하는 듯..

[링크 : https://stackoverflow.com/questions/45091269/how-to-print-current-working-directory-in-psql-console]

Posted by 구차니
Linux2019. 9. 2. 15:30

-F '\t' 

[링크 : https://kldp.org/node/120883]

 

-F fs
--field-separator fs
Use fs for the input field separator (the value of the FS predefined variable).

[링크 : https://linux.die.net/man/1/awk]

 

+

출력은 탭으로 안되는데(기본값이 스페이스)

OFS

The output field separator, a space by default.

 

여러번 시도해보니.. awk'{}' OFS='\t'만 먹는다. 환경변수로 인식을 하는 듯?

awk '{split($5,a,"-"); print $1,$2,$3,a[1]}' OFS='\t' file.bed > test.bed

[링크 : https://www.unix.com/shell-programming-and-scripting/264368-awk-output-seperated-tab.html]

 

+

$ cat filename | awk -F '\t' '{$2="";print $0;}' OFS='\t' | sed 's/<.*//'

두번째 값을 날리고, 끝에 탭이 하나씩 남아서 따라오는걸 없애는 법 (두번째가 마지막 column이라고 가정)

[링크 : https://askubuntu.com/questions/232606/stdout-string-manipulate-delete-all-after-a-word-per-line]

 

+

끝이 스페이스로 끝날때 날리기

sed -i 's/[[:space:]]*$//' <name-of-file.ldif>

[링크 : https://www.theurbanpenguin.com/remove-trailing-spaces-using-sed/]

'Linux' 카테고리의 다른 글

awk 치환(삭제)  (0) 2019.09.02
tail과 cat 합치기  (0) 2019.09.02
awk 특정 열 제외하기  (0) 2019.09.02
linux 수동 trim  (0) 2019.08.16
jq - json in linux command line  (0) 2019.08.16
Posted by 구차니
Linux2019. 9. 2. 13:03

아래는 3번과 5번에 대해서 열을 날리는 예제

 

$ cat temp.txt | awk '{$3=$5=""; print $0}'

C1 C2  C4  C6 C7 C8 C9 C10

[링크 : https://ondemand.tistory.com/238]

 

+

단, 구분자를 제외하고 날리기 때문에 하나의 빈 구분자가 추가되는 식으로 출력되니 주의

'Linux' 카테고리의 다른 글

tail과 cat 합치기  (0) 2019.09.02
awk 구분자 탭으로 인식시키기  (0) 2019.09.02
linux 수동 trim  (0) 2019.08.16
jq - json in linux command line  (0) 2019.08.16
awk NR, NF  (0) 2019.08.12
Posted by 구차니

그런거 없다~ -_ㅠ

 

아무래도.. awk의 힘을 빌려야 할 듯..

[링크 : https://stackoverflow.com/questions/26701735/]

'프로그램 사용 > postgreSQL' 카테고리의 다른 글

pg_restore  (0) 2019.09.03
postgresql working directory  (0) 2019.09.02
postgresql \copy에서 시작 몇줄 무시하기  (0) 2019.09.02
postgresql custom database dump 복구하기  (0) 2019.09.02
postgresql generate_series()  (0) 2019.08.28
Posted by 구차니

그런거 없다 -_-

tail -n+3을 통해서 앞의 3줄을 날리고 하는걸 추천하는 듯...

 

tail -n+3 myfile.csv

[링크 : https://stackoverflow.com/questions/37368845/postgresql-copy-skip-first-two-lines-off-csv]

'프로그램 사용 > postgreSQL' 카테고리의 다른 글

postgresql working directory  (0) 2019.09.02
postgresql \copy에서 컬럼 무시하기  (0) 2019.09.02
postgresql custom database dump 복구하기  (0) 2019.09.02
postgresql generate_series()  (0) 2019.08.28
where 1=1  (4) 2019.08.27
Posted by 구차니

 

 

export
pg_dump -U db_user -W -F t db_name > /path/to/your/file/dump_name.tar

import
pg_restore -d db_name /path/to/your/file/dump_name.tar -c -U db_user

[링크 : https://axiomq.com/blog/backup-and-restore-a-postgresql-database/]

 

[링크 : https://www.postgresql.org/docs/9.4/backup-dump.html]

[링크 : https://www.postgresql.org/docs/8.1/backup.html]

[링크 : https://www.postgresql.org/docs/8.1/app-pgrestore.html]

'프로그램 사용 > postgreSQL' 카테고리의 다른 글

postgresql \copy에서 컬럼 무시하기  (0) 2019.09.02
postgresql \copy에서 시작 몇줄 무시하기  (0) 2019.09.02
postgresql generate_series()  (0) 2019.08.28
where 1=1  (4) 2019.08.27
join  (0) 2019.08.27
Posted by 구차니