grep还是一个简单的脚本? [英] grep or a simple script?

查看:124
本文介绍了grep还是一个简单的脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我发现这个非常有用的论坛和友好的人,我有一个小请求。


我使用AIX Unix,想知道是否有一个简单的方法如何在两个文件之间做一种比较。我应该使用一些grep或脚本吗?


我有2个文本文件,让我们将它们命名为file1和file2。


我是什么需要:


我想逐行读取file1 - file1的某个字段或更好的2个字段,并查找file2中的信息。


更具描述性:我想从file1中提取位置10-15的field1和位置25-31的field2,然后搜索或查找相同的信息是否在file2中的某个位置。当没有时,我想输出field1& file2关闭文件1并没有退出文件2.


让我们说file1包含类似的东西:


123232 3232 2323 2323123123213 trterert


和file2例如


123232 3232 2323 2323123123213 XXXXXXXX


并让's'说我想要123232&来自file1的trterert将在file2中搜索==>我得到一个错误因为脚本只能找到123232而不是trterert .....


如果有人可以帮助我或推荐一个链接或适当的命令或脚本,我会非常高兴。


我只需要在一个文件中查看一些记录 - 如果它们在另一个文件中可用...


有什么建议吗?谢谢。

Since I found this very helpful forum and friendly people, I have a small request.

I use AIX Unix and would like to know if there''s a simple way how to do a kind of compare between two files. Should I use some grep or script?

I have 2 text files, let''s name them file1 and file2.

What I need:

I want to read line by line file1 - certain field or better 2 fields of the file1 and look up the information in the file2.

To be more descriptive: I''d like to extract field1 at position 10-15 and field2 at position 25-31 from file1 and search or find if the same information is somewhere inside the file2. When no, I''d like to output the field1 & field2 off the file1 doesn''t exit in file2.

let''s say file1 contains something like:

123232 3232 2323 2323123123213 trterert

and file2 e.g.

123232 3232 2323 2323123123213 XXXXXXXX

and let''s say I want 123232 & trterert from file1 to be searched in file2 ==> I get an "error" because the script would find only 123232 and not trterert.....

I''d be more than happy if someone can help me out or recommend a link or appropriate command or script.

I just need to check some record(s) in one file - and if they''re available in the other file...

Any suggestions please? Thanks.

推荐答案

检查以下脚本:
check the below script:
< span class =codeLinkonclick =Blur(this,this.parentNode.parentNode,getChildren(this),true);>展开 | 选择 | Wrap | 行号


谢谢......如果不是每条记录都有相同的列布局?是否有可能从第一个文件中的某个位置提取这两个字段并在第二个文件中查找它们?
Thanks...and if not every record has the same column layout? Is there a possibility extract those 2 fields from certain position in the first file and look them up in the second file?



谢谢.. 。如果不是每条记录都有相同的列布局?是否有可能从第一个文件中的某个位置提取这两个字段并在第二个文件中查找它们?
Thanks...and if not every record has the same column layout? Is there a possibility extract those 2 fields from certain position in the first file and look them up in the second file?



你如何从第一个文件中提取''那两个字段'?

我的意思是必须有一些逻辑..


与上面的代码一样,我们确定要检查第1和第5个字段..

现在,如果您的列布局如下所示:


第一条记录:5栏

第二条记录:3栏

3条记录:7栏.....等


我们会在哪个基础上找到记录中的字段?


How would you extract ''those 2 fields'' from first file?
I mean there must be some logic..

Like in above code we are sure that 1st and 5th field is to be checked..
Now if your column layout is something like below:

1st record:5 columns
2nd record:3 columns
3 record:7 columns..... etc

on which basis we''ll find fields from records?


这篇关于grep还是一个简单的脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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