방문자
Scientist. Husband. Daddy. --- TOLLE. LEGE
[1] 이 블로그는 대한민국 저작권법(28조)과 U.S. Copyright Act (17 USC. §107)에 정의된 "저작권물의 공정한 이용원칙 | the U.S. fair use doctrine" 을 따릅니다. [2] 저작권(© 최광민)이 명시된 모든 글과 번역문들에 대해 (1) 원글의 URL 주소링크를 밝히지 않은 모든 형태의 (2) 전문 복제-배포, (3) 임의수정 및 자의적 본문 발췌, (4) 화면캡처 및 배포를 금지합니다. [3] 아울러 이 블로그의 내용을 AI 학습용으로 이용하는 것 역시 금지합니다. [운영] [대문으로] [방명록]
블로그 후원하기
[한국] 하나은행 (최광민): 376-910-500-183-07
[미국] 벤모 Venmo: @pay4kc
[국제] 페이팔 PayPal: @pay4kc
법어
草人종/정 광미누/스님 가라사대: |
삶/은 계란이요 |
죽/은 대나무 |
난草/ 人가 ! |
블로그 내부검색
주제
연재
한 주 BEST
- [© 최광민] 예수 vs. 예수 #02: 예수는 언제부터 신이었을까?
- [© 최광민] 예수 vs. 붓다 #5: 예수와 기독교 교부들은 윤회와 환생을 가르쳤을까?
- [© 최광민] 전쟁에 관한 기독교 초기교부들의 견해
- [© 최광민] 예수 vs. 예수 #07: 삼위일체 개념은 어디서 유래했을까?
- [© 최광민] 예수 vs. 붓다 #1: 소위 "불교계통" 복음서들의 정체: {이사전}, {보병궁 복음서}, {유란시아書}, {임마누엘의 탈무드}
- [© 최광민] 모세 vs. 아케나텐 #1: 소위, {아크나톤 18계명 / 아톤 18계명}의 정체
- [© 최광민] 예수 vs. 예수 #11: 크리스마스의 기원과 동방박사의 별 (합본)
- [© 최광민] 랍비 카두리의 메시아, 예수
- [© 최광민] 주교 vs. 미트라(스) + 다곤 + 키벨레 : 패션과 음모
- [© 최광민] 로마카톨릭 vs. 프로테스탄트 #03: 예정과 자유의지, 그리고 구원
최신 포스팅
awk for Unix -> Mac file conversion
Labels:
Informatics
이메일로 전송BlogThis!X에 공유Facebook에서 공유
Convert Mac to Unix - Or ^M to CR
***
To use awk to convert a Mac OS file to Unix, at the Unix prompt, enter:
awk '{ gsub("\r", "\n"); print $0;}' macfile.txt; unixfile.txt
***
To convert a Unix file to Mac OS using awk, at the command line, enter:
awk '{ gsub("\n", "\r"); print $0;}' unixfile.txt; macfile.txt
#!/bin/sh
for filename in ./Test/*.txt
do
echo $filename
perl -pi -e 's/rn?/n/g' "$filename"
done
http://obswww.unige.ch/~segransa/HELP/replace.html
tr
Sous emacs : remplacer un carriage return par un ¨;¨
esc-x query-replace Ctrl q Ctrl J
par ;
Ctrl q donne acces aux caracteres de controle
Ctrl j correspond au renturn.
Sous emacs : remplacer 2 carriage return par un seul ;
esc-x query-replace Ctrl q Ctrl j Ctrl q Ctrl j
par Ctrl q Ctrl j
The Unix program tr is used to translate between two sets of characters. Characters specified in one set are converted to the matching character in the second set. Thus, to convert the Ctrl-m of a Mac OS text file to the line feed (Ctrl-j) of a Unix text file, at the Unix command line, enter:
tr '\r' '\n' < macfile.txt > unixfile.txt
Here, \r and \n are special escape sequences that tr interprets as Ctrl-m (a carriage return) and Ctrl-j (a line feed), respectively. Thus, to convert a Unix text file to a Mac OS text file, enter:
tr '\n' '\r' < unixfile.txt > macfile.txt
Note: The escape sequences must be surrounded by quotes for these commands to work.
awk
To replace all letters, numbers, parenthesis and "_" and "^" by "-" in the file head enter :
nawk '{ gsub(/[a-zA-Z0-9"^""_""("")"]/, "+");print $0;}' head.csv
To use awk to convert a Mac OS file to Unix, at the Unix prompt, enter:
awk '{ gsub("\r", "\n"); print $0;}' macfile.txt > unixfile.txt
To convert a Unix file to Mac OS using awk, at the command line, enter:
awk '{ gsub("\n", "\r"); print $0;}' unixfile.txt > macfile.txt
On some systems, the version of awk may be old and not include the function gsub. If so, try the same command, but replace awk with gawk or nawk.
To replace the remove all lines starting with #, enter :
awk '{if ( substr($0,1,1)!="#") print $0}' list_2mass.tsv
To replace the remove all lines starting with either # or carriage return or SPACE, enter :
awk '{if (substr($0,1,1)!="#"&&substr($0,1,1)!='\n'&&substr($0,1,1)!=" ") print $0}' list_2mass.tsv
egrep
It can also be done with egrep
egrep -v '(^\#|^ $|^$|^ $)' < list2.tsv
sed
14 of the most common sed commands for one-line use.
Replace a newline to \\followed by a newline
sed 's/$/\\\\/' final.tex
Double space a file
sed G file
Triple space a file
sed 'G;G' file
Under UNIX: convert DOS newlines (CR/LF) to Unix format
sed 's/.$//' file # assumes that all lines end with CR/LF
sed 's/^M$// file # in bash/tcsh, press Ctrl-V then Ctrl-M
Under DOS: convert Unix newlines (LF) to DOS format
sed 's/$//' file # method 1
sed -n p file # method 2
Delete leading whitespace (spaces/tabs) from front of each line
# (this aligns all text flush left). '^t' represents a true tab
# character. Under bash or tcsh, press Ctrl-V then Ctrl-I.
sed 's/^[ ^t]*//' file
Delete trailing whitespace (spaces/tabs) from end of each line
sed 's/[ ^t]*$//' file # see note on '^t', above
Delete BOTH leading and trailing whitespace from each line
sed 's/^[ ^t]*//;s/[ ^]*$//' file # see note on '^t', above
Substitute "foo" with "bar" on each line
sed 's/foo/bar/' file # replaces only 1st instance in a line
sed 's/foo/bar/4' file # replaces only 4th instance in a line
sed 's/foo/bar/g' file # replaces ALL instances within a line
Substitute "foo" with "bar" ONLY for lines which contain "baz"
sed '/baz/s/foo/bar/g' file
Delete all CONSECUTIVE blank lines from file except the first.
# This method also deletes all blank lines from top and end of file.
# (emulates "cat -s")
sed '/./,/^$/!d' file # this allows 0 blanks at top, 1 at EOF
sed '/^$/N;/\n$/D' file # this allows 1 blank at top, 0 at EOF
Delete all leading blank lines at top of file (only).
sed '/./,$!d' file
Delete all trailing blank lines at end of file (only).
sed -e :a -e '/^\n*$/N;/\n$/ba' file
If a line ends with a backslash, join the next line to it.
sed -e :a -e '/\\$/N; s/\\\n//; ta' file
If a line begins with an equal sign, append it to the
# previous line (and replace the "=" with a single space).
sed -e :a -e '$!N;s/\n=/ /;ta' -e 'P;D' file
Perl
To convert a Mac OS text file to a Unix text file using Perl, at the Unix shell prompt, enter:
perl -p -e 's/\r/\n/g' < macfile.txt > unixfile.txt
To convert from a Unix text file to a Mac OS text file with Perl, at the Unix shell prompt, enter:
perl -p -e 's/\n/\r/g' < unixfile.txt > macfile.txt
이메일로 전송BlogThis!X에 공유Facebook에서 공유
Labels:
Informatics
Scientist. Husband. Daddy. --- TOLLE. LEGE
[1] This blog complies with the "Fair Use Doctrine" as defined in Article 28 of the Republic of Korea Copyright Act and the U.S. Copyright Act (17 USC. §107). [2] Regarding copyrighted (© Kwangmin Choi) articles and translations, the following actions are prohibited (1) without providing a link to the original URL: (2) Full reproduction and distribution, (3) Unauthorized modification and arbitrary excerpting, and (4) Screen capturing and distribution. [3] Additionally, using the content of this blog for AI training is strictly prohibited. [운영] [대문으로] [방명록]
블로그 후원하기
[한국] 하나은행 (최광민): 376-910-500-183-07
[미국] 벤모 Venmo: @pay4kc
[국제] 페이팔 PayPal: @pay4kc

