我正在做一个 ldapsearch 查询,它返回的结果如下
John Joe [email protected] +1 916 662-4727 Ann Tylor [email protected] (987) 654-3210 Steve Harvey [email protected] 4567893210 (321) 956-3344 ...
正如您所看到的,每个个人记录输出之间有一个空格,电话号码可能以 +1 开头,也可能不是,数字或括号之间可能有空格,最后在个人记录之间有两个空格。例如:
我想将这些条目转换为以下格式:
John,Joe,[email protected],(916) 662-4727
Ann,Tylor,[email protected],(987) 654-3210
Steve,Harvey,[email protected],(456) 789-3210,(321) 956-3344
...
所以基本上用一个逗号“,”替换一个空格,用 替换两个空格,这样最后我每行有一个个人记录(逗号分隔)。例子:
我正在尝试 awk 并设法用“,”替换
<blank><blank> to double comma ",,".
But can't figure out how to turn ",," to <RETURN>
11/22/2017 -******** 更新 *****--------- 11/22/2017
我让这条赛道太拥挤了。我会发布一个包含更多细节的新问题。
如果您的 Input_file 与所示示例相同,那么以下内容awk
可能对您有所帮助。
awk --re-interval '{gsub(/[0-9]{3}-[0-9]{4} +/,"&\n");print}' Input_file
我有旧版本,awk
所以我--re-interval
在新版本中提到过,awk
无需提及。
说明:在此处也添加解决方案的说明。
awk --re-interval '{ ##using --re-interval to use the extended regex as I have old version of awk.
gsub(/[0-9]{3}-[0-9]{4} +/,"&\n"); ##Using gsub utility(global substitute) of awk where I am checking 3 continuous dots then dash(-) then 4 continuous digits and till space with same regex match and NEW LINE.
print ##printing the line of Input_file
}' Input_file ##Mentioning the Input_file here.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句