[20190710]windows文字格式.txt

lfree發表於2019-07-13

[20190710]windows文字格式.txt

--//大家都知道windows文字格式是回車換行,與linux的文字格式存在一點點不同。
--//最近在windows下遇到一些問題,做1個記錄。

D:\>seq 4 > d:\a
D:\>ls -l a
-rw-rw-rw-   1 user     group          12 Jul 10 17:33 a

D:\>xxd -c 16 a
0000000: 310d 0a32 0d0a 330d 0a34 0d0a            1..2..3..4..

--//你可以發現生成的文字格式是windows的文字格式。如果執行如下:
D:\>seq 4 | xargs -iQ C:\WINDOWS\system32\echo -e "create table tQ as select level id from dual connect by level<=power(4,Q)"
)as select level id from dual connect by level<=power(4,1
)as select level id from dual connect by level<=power(4,2
)as select level id from dual connect by level<=power(4,3
)as select level id from dual connect by level<=power(4,4
--//看到的輸出很奇怪。
·
D:\>seq 4 | xargs -iQ C:\WINDOWS\system32\echo -e "create table tQ as select level id from dual connect by level<=power(4,Q)" > a

--//如果使用vim開啟,可以發現實際上這裡的Q在替換時帶\r字元的。
create table t1
 as select level id from dual connect by level<=power(4,1
)
create table t2
 as select level id from dual connect by level<=power(4,2
)
create table t3
 as select level id from dual connect by level<=power(4,3
)
create table t4
 as select level id from dual connect by level<=power(4,4
)
--//也就是透過傳遞過來的是帶有\r字元。
--//也就是要加一個過濾刪除裡面的\r字元。執行如下:

D:\>seq 4 | tr -d "\r" | xargs -iQ C:\WINDOWS\system32\echo -e "create table tQ as select level id from dual connect by level<=power(4,Q);"
create table t1 as select level id from dual connect by level<=power(4,1);
create table t2 as select level id from dual connect by level<=power(4,2);
create table t3 as select level id from dual connect by level<=power(4,3);
create table t4 as select level id from dual connect by level<=power(4,4);

--//這樣小問題浪費半個小時,做一個記錄很有必要。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2650452/,如需轉載,請註明出處,否則將追究法律責任。

相關文章