与shell脚本编辑文本格式 [英] Edit text format with shell script
本文介绍了与shell脚本编辑文本格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使文本编辑的脚本。在这种情况下,我有一个名为text.csv一个文本文件,其内容为:
I am trying to make a script for text editing. In this case I have a text file named text.csv, which reads:
first;48548a;48954a,48594B
second;58757a;5875b
third;58756a;58576b;5867d;56894d;45864a
我想使文本格式是这样的:
I want to make text format to like this:
first;48548a
first;48954a
first;48594B
second;58757a
second;5875b
third;58756a
third;58576b
third;5867d
third;56894d
third;45864a
什么是命令,我应该使用,使这种情况发生?
What is command should I use to make this happen?
推荐答案
我想这样做是AWK。
假设你的第一行应该有一个;
,而不是,
:
Assuming your first line should have a ;
instead of a ,
:
$ awk -F\; '{for(n=2; n<=NF; n++) { printf("%s;%s\n",$1,$n); }}' input.txt
未经检验。
这篇关于与shell脚本编辑文本格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文