首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我需要从文件中的列子集中找到一个字符串,而不是从整个文件中找到一个字符串。

我需要从文件中的列子集中找到一个字符串,而不是从整个文件中找到一个字符串。
EN

Stack Overflow用户
提问于 2016-03-23 14:52:07
回答 2查看 61关注 0票数 0

我正在使用LINUX,我希望使用shell来实现这一点。

我想从字段db2中提取字符串“”,这个字段对应于“”字段,这个字段是由/tab分隔的,而且我不能使用固定位置,因为它的大小是可变的。

的实际文件提取是:提供了2条记录,从时间戳开始。

Jeff Y:格式化数据

代码语言:javascript
复制
create_ts   id  tags    title   body    answers

2011-01-03T20:52:52.880 5   **nosql^&^rdbms^&^database-recommendation** what are the differences between nosql and a traditional rdbms  what are the differences between nosql and a traditional rdbms   over the last few months  nosql has been frequently mentioned in the technical news  what are its most significant features relative to a traditional rdbms  at what level  physical  logical  do the differences occur   where are the best places to use nosql  why      nosql is a kind of database that doesn t have a fixed schema like a traditional rdbms does   with the nosql databases the schema is defined by the developer at run time   they don t write normal sql statements against the database  but instead use an 
2011-01-04T14:26:06.730 162 sql^&^explain-plan^&^db2    what does hsjoin mean in an explain plan    i have the following explain plan results from a query on my db2 database   0 select statement   estimated costs    5 928e 02  timerons           1 return            2 hsjoin                3  o  fetch ltbp                    4 ixscan ltbp m  key columns   0                5  i  fetch ltbk                    6 ixscan ltbk v  key columns   0   what does the hsjoin on line 2 mean    it s a hash join  
2011-01-07T16:44:52.210 394 **database-recommendation^&^feature comparison^&^permissions**  which database engines will allow me to grant revoke on a specific column   if i have a table with a single column of sensitive data  and i want to grant broad use of the table without exposing that one column  i know that i can create a view that gives them access to all the non sensitive columns  however  postgresql allows you to grant column level permissions in the form of  grant select  col1     coln  on table to role    are there other engines which provide this capability     sql server 2000  2005  2008 has this capability  grant   all   privileges              permission     column       n             n            on   class      securable   to 
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-03-23 19:35:17

您的示例数据没有显示选项卡划界,但假设所有字段实际上都是选项卡分隔的:

使用awk,您需要拆分标签分隔符上的第三个字段,并在结果中查找您的标记:

代码语言:javascript
复制
awk -F"\t" '{split($3,a,/\^&\^/);for(t in a)if(a[t]=="db2"){print;next}}'
票数 0
EN

Stack Overflow用户

发布于 2016-03-23 15:04:37

awk去营救!如果没有基于char计数的区域分隔标记,则可以限制模式匹配。

代码语言:javascript
复制
$ awk 'substr($0,start,length)~/pattern/' file

例如,如果感兴趣的部分以14和9个字符的长度开始,则搜索模式abc。

代码语言:javascript
复制
$ awk 'substr($0,14,9)~/abc/' file

如果数据是分隔的,例如使用选项卡,并且希望将搜索限制为字段2,则可以这样做。

代码语言:javascript
复制
$ awk -F'\t' '$2~/abc/' file

当然,这些只是猜测,直到您有了一个具体的示例来演示真正的问题并验证脚本。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36181481

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档