linux每行第7个字符串,在Linux shell中,如何處理多行字符串的每一行?

42

Use this (it is loop of reading each line from file file)

使用它(它是從文件文件中讀取每一行的循環)

cat file | while read -r a; do echo $a; done

where the echo $a is whatever you want to do with current line.

echo $ a是你想用當前行做什么的。

UPDATE: from commentators (thanks!)

更新:來自評論員(謝謝!)

If you have no file with multiple lines, but have a variable with multiple lines, use

如果沒有多行文件,但有多行變量,請使用

echo "$variable" | while read -r a; do echo $a; done

UPDATE2: "read -r" is recommended to disable backslashed (\) chars interpretation (check mtraceur comments; supported in most shells). It is documented in POSIX 1003.1-2008 http://pubs.opengroup.org/onlinepubs/9699919799/utilities/read.html

UPDATE2:建議使用“read -r”來禁用反斜杠(\)字符解釋(檢查mtraceur注釋;在大多數shell中都支持)。它在POSIX 1003.1-2008中有記錄http://pubs.opengroup.org/onlinepubs/9699919799/utilities/read.html

By default, unless the -r option is specified, shall act as an escape character. .. The following option is supported: -r - Do not treat a character in any special way. Consider each to be part of the input line.

默認情況下,除非指定了-r選項,否則

將充當轉義字符。 ..支持以下選項:-r - 不要以任何特殊方式處理 字符。考慮每個都是輸入行的一部分。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值