在Linux中的文件中搜索字符在线中的字符并进行编辑
我有一个要加载到Linux中数据库中的分界字段文件。问题是每个行中的分隔字段数并不相同。因此,我需要一个shell脚本来迭代每行,并检查定界线字符的出现数量,我需要每行定界线字符13个出现。因此,如果我有10个,例如,我需要在此行的末尾添加2个额外的分界符字符。
现在我所拥有的就是这样:
#!/usr/bin/bash
while read p; do
if
-----------
fi
done <myDataFile
I have a delimited fields file that I want to load into the database in Linux. The thing is that the number of delimited fields is not the same in every row. So, I need a shell script to iterate over each line and check for the number of occurrences of the delimiter character, I need 13 occurrences of the delimiter character per line. So, if I have 10 for example, I need to add 2 extra delimiter characters at the end of this line.
Now all that I have got is this:
#!/usr/bin/bash
while read p; do
if
-----------
fi
done <myDataFile
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
提供的信息相当稀疏。
你的定界符是什么?
定界符(引用)可以在任何字段中发生吗?
对于简单的情况,例如分隔符=“ |”并且在字段中不发生,这是一个快速
awk
hack。而且尴尬:
尴尬变得漂亮而解释:
The information provided is rather sparse.
What's your delimiter?
Can the delimiter (quoted) occur in any of the fields?
For a simple case, e.g. delimiter="|" and doesn't occur inside the fields here's a quick
awk
hack.And the awk:
And the awk made pretty and explained: