如何解析&使用 UNIX 脚本更新平面文件
我正在尝试解析一个平面文件,其中包含标题列 名称公司详细信息状态等
(其中数据本身不同)。
当我使用该文件作为输入运行脚本时,我需要更新 STATUS 列,并根据其他列的详细信息更新 STATUS。
sed 和显而易见,vi 不能使用。请帮忙。
我试图解析的文件的摘录是: 我试图解析的文件的摘录(针对该问题提出的问题)是:
34 /* 1 2 3 4 5 6
35 /*3456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
36 YYNNN LOCAL1 TRANSFER-CDM(仅)=>local.transfer LOCAL
37 YYNNN LOCAL2 EXCHANGE-CATIA =>IGES/DXF/STEP LOCAL
38 YYNNN ACIS1 C AutoWeb 媒体服务 CCX
39 YYNNN ACNC1 C Auto/Con 公司 CCX
40 YYNNN ACST1 C Accurcast Inc CCX
41 YYNNN AAGD1 C Algonquin Automotive CCX
现在我需要做的是解析这个平面文件,并将第 6 列添加为状态。
我尝试过:
awk '/23861/ { $0=$0 "|Processed" } {print}' 输入
where - 1.awk 命令 wil srch 4 模式
2.大括号中的内容将在最后一列中更新
但这也给了我错误: 如果该列与行中的字符串匹配,则会在末尾添加带有“|Processed”字符串的列。
如果我再次运行该命令,它会在末尾再次添加该字符串。
该行看起来像
JAN FEB MAR |已处理 |已处理
现在,我想要的是将以前的“|已处理”值替换为新值(根据条件)并相应地更新该值
I am trying to parse a flat file which has columns by the titlesNAME COMPANY DETAILS STATUS etc
(where the data is dissimilar among itself).
I need to update the STATUS
column when I run a script with that file as input, with the STATUS being updated depending on other columns' details.
sed & vi cannot be used, as obvious. Please help.
An excerpt of the file that I am trying to parse is :
an excerpt from the file I am trying to parse, for which the question is asked, is :
34 /* 1 2 3 4 5 6
35 /*3456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
36 YYNNN LOCAL1 TRANSFER-CDM(only) =>local.transfer LOCAL
37 YYNNN LOCAL2 EXCHANGE-CATIA =>IGES/DXF/STEP LOCAL
38 YYNNN ACIS1 C AutoWeb Media Services CCX
39 YYNNN ACNC1 C Auto/Con Corporation CCX
40 YYNNN ACST1 C Accurcast Inc CCX
41 YYNNN AAGD1 C Algonquin Automotive CCX
Now what I need to do is to parse this flat file and the 6th column would be added as STATUS.
I have tried:
awk '/23861/ { $0=$0 "|Processed" } {print}' input
where - 1.awk command wil srch 4 the pattern
2.that thng in curly brackets will update in last column
But this too is giving me error :
it is adding the column at the end with the "|Processed" string if it matches the string in the line.
If I run that command again, it adds again that string at the end.
That row looks like
JAN FEB MAR |Processed |Processed
Now, what I want is to replace that previous “|Processed” value with the new one(as per the condition) and update that value accordingly
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你应该定义
什么细节??
例如,如果 DETAILS 列值 ==1 则进行更新,您可以执行以下操作:
如果您想检查公司名称是否包含“google”,则进行更新:
您必须定义详细信息 其他列。
You should define
what details??
e.g. if DETAILS column value ==1 then do the update, you can do:
if you want to check, if the name of company contains "google", you do the update:
you have to define the details of other columns.
您可以使用 awk:
You can use awk: