脚本,unix,比较 [英] script,unix,compare

查看:197
本文介绍了脚本,unix,比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文件...

file1:

002009092312291100098420090922111
010555101070002956200453T+00001190.81+00001295.920010.87P
010555101070002956200449J+00003128.85+00003693.90+00003128
010555101070002956200176H+00000281.14+00000300.32+00000281

文件2:

002009092410521000098420090709111
010560458520002547500432M+00001822.88+00001592.96+00001822
010560458520002547500432D+00000106.68+00000114.77+00000106

在这两个文件中的每条记录开始01 ....字符串从第3个字符到第25个字符直到字母是关键...
基于这个key..i有比较两个文件.....如果有任何记录匹配在文件2 ...然后我必须替换记录
在file1 ...或者如果它不匹配...则附加它。

in both files in every record starting with 01....the string from 3rd char to 25th char..i.e upto alphabet is the key... based on this key..i have to compare two files .....and if there is any record matching in file 2...then i have to replace that record in file1...or else append it if it wont match....

请帮助ASAP

推荐答案

好吧,这是一个相当不具体我们将能更好地帮助我们,如果你解释你做了什么以及在哪里卡住了。

Well, this is a fairly unspecific (and basic) programming question. We'll be better able to help us if you explain exactly what you did and where you got stuck.

此外,它看起来有点像功课,人们持谨慎态度,给予家庭作业的问题太多帮助,因为它可能看起来像欺骗

Also, it looks a bit like homework, and people are wary of giving too much help on homework problems, as it might look like cheating.

为您开始:


  • 我建议你的Perl 来解决这个问题,但 awk 或其他脚本语言也会做。我建议反对sh / bash,因为他们对文本操纵弱;

  • 首先编写一个过滤从01开始的记录的Perl程序。然后提取密钥并将其放入一个散列(Perl结构)中。

  • I'd recommend Perl to solve this, but awk or another scripting language will also do. I'd recommend against sh/bash, as they are weak on text manipulation; also combining grep et al will become rather cumbersome.
  • First write a Perl program that filters records starting with 01. Then extract the key and put it into a hash (a Perl structure). Then output a new, combined file as required.

如果您仍然遇到问题,请随时编辑您的问题。

Feel free to edit your question if you are still having trouble.

这篇关于脚本,unix,比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆