在 shell 脚本中读取很长的一行而不分成多行
我有一个包含很长行数据的文件。当我尝试使用 shell 脚本读取时,数据会分成多行,即在某些点中断。
示例行:
B_18453583||Active|917396140129|405819121107402|Active|7396140129||7396140129|||||||||18-MAY-10|||||18-MAY-10|405819121107402|Outgoing International Calls,Outgoing Calls,WAP,Call Waiting,MMS,Data Service,National Roaming-Voice,Outgoing International Calls except home country,Conference Call,STD,Call Forwarding-Barr,CLIP,Incoming Calls,INTSNS,WAPSNS,International Roaming-Voice,ISD,Incoming Calls When Roaming Internationally,INTERNET||For You Plan
I have a file which has very long rows of data. When i try to read using shell script, the data comes into multiple lines,ie, breaks at certain points.
Example row:
B_18453583||Active|917396140129|405819121107402|Active|7396140129||7396140129|||||||||18-MAY-10|||||18-MAY-10|405819121107402|Outgoing International Calls,Outgoing Calls,WAP,Call Waiting,MMS,Data Service,National Roaming-Voice,Outgoing International Calls except home country,Conference Call,STD,Call Forwarding-Barr,CLIP,Incoming Calls,INTSNS,WAPSNS,International Roaming-Voice,ISD,Incoming Calls When Roaming Internationally,INTERNET||For You Plan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
||||||||
所有这些都是一行的内容。
我使用这样的正常读取:
输出如下:
||||||||
All this is the content of a single line.
I use a normal read like this :
The output comes as:
||||||||
我如何在单行中打印所有内容?
请帮忙。
谢谢
||||||||
How do i print all in single line??
Please help.
Thanks
这是因为分词。一种更简单的方法来做到这一点(也可以通过 无用的使用
cat
来解散)是这样的:详细解释一下:
man bash
。IFS=
是必要的,以避免 IFS 中的任何字符从 $REPLY 的开头和结尾被删除。-r
避免专门解释文本中的反斜杠。-d $'\n'
按换行符分割行。cat
这样的贪婪命令吃掉所有数据。This is because of word splitting. An easier way to do this (which also disbands with the useless use of
cat
) is this:To explain in detail:
man bash
.IFS=
is necessary to avoid that any characters in IFS are stripped from the start and end of $REPLY.-r
avoids interpreting backslash in text specially.-d $'\n'
splits lines by the newline character.cat
eating all of it.您需要正确的引用。在您的情况下,您应该使用命令
read
:You need proper quoting. In your case, you should use the command
read
: