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

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

问题描述

我有两个文件...

文件1:

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日char..i.e高达字母是关键...
在此基础上key..i要比较两个文件.....如果有文件2任何记录匹配...然后我不得不更换记录
在文件1 ...不然追加它,如果它不会匹配......

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....

请尽快帮忙

推荐答案

好了,这是一个相当不确定的(和基本)编程问题。我们将能更好地帮助我们,如果你解释你做了什么以及在哪里卡住了。

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的,因为他们是在文本操作较弱;还结合的grep等人将变得相当麻烦。

  • 首先编写过滤与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天全站免登陆