for loop 的單位 - Linux

By Dorothy
at 2009-06-16T00:01
at 2009-06-16T00:01
Table of Contents
※ 引述《Xphenomenon (啦 )》之銘言:
: 我有一個檔案內容如下,以 tab 鍵切開:
: test.txt
: a 1
: b 2
: c 3
: d 4
: for i in `cat test.txt`; do echo $i; done
: 輸出:
: a
: 1
: b
: 2
: c
: 3
: d
: 4
: 請教:
: 我如何能夠讓 i 包含一整行,因為我需要近一步的把欄位切開,
: 我需要同時處理如 a 和 1 的值。麻煩了,感謝! :>
=============>
You need to know IFS special variable.
please try below.
IFS=''
for i in `cat test.txt` ; do echo $i ; done
unset IFS
for i in `cat test.txt` ; do echo $i ; done
$> man bash
IFS The Internal Field Separator that is used for word splitting
after expansion and to split lines into words with the read
builtin command. The default value is ``<space><tab><newline>''.
--
: 我有一個檔案內容如下,以 tab 鍵切開:
: test.txt
: a 1
: b 2
: c 3
: d 4
: for i in `cat test.txt`; do echo $i; done
: 輸出:
: a
: 1
: b
: 2
: c
: 3
: d
: 4
: 請教:
: 我如何能夠讓 i 包含一整行,因為我需要近一步的把欄位切開,
: 我需要同時處理如 a 和 1 的值。麻煩了,感謝! :>
=============>
You need to know IFS special variable.
please try below.
IFS=''
for i in `cat test.txt` ; do echo $i ; done
unset IFS
for i in `cat test.txt` ; do echo $i ; done
$> man bash
IFS The Internal Field Separator that is used for word splitting
after expansion and to split lines into words with the read
builtin command. The default value is ``<space><tab><newline>''.
--
Tags:
Linux
All Comments
Related Posts
兩台ubuntu如何共享網路資源?

By Harry
at 2009-06-15T23:20
at 2009-06-15T23:20
兩台ubuntu如何共享網路資源?

By Jack
at 2009-06-15T23:08
at 2009-06-15T23:08
Fedora 10 安裝MRTG

By Freda
at 2009-06-15T22:51
at 2009-06-15T22:51
用iwlist指令scan到非常多的AP?

By Leila
at 2009-06-15T21:44
at 2009-06-15T21:44
for loop 的單位

By Dora
at 2009-06-15T20:44
at 2009-06-15T20:44