我使用的是LINUX,我想用shell来实现这一点。
我想用粗体从字段中提取字符串“db2”,这对应于“tags”字段,该字段由/tab分隔,不能使用固定位置,因为它的大小是可变的。
实际的文件提取是:显示2条记录,从时间戳开始。
[杰夫Y:格式化数据]

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

最佳答案

您的示例数据没有显示制表符分隔,但假设所有字段实际上都是制表符分隔的:
使用awk,需要拆分标记分隔符上的第三个字段,并在结果中查找标记:

awk -F"\t" '{split($3,a,/\^&\^/);for(t in a)if(a[t]=="db2"){print;next}}'

关于linux - 我需要从文件中的列子集中而不是整个文件中找到字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36181481/

10-14 14:24
查看更多