我正在使用 LINUX,我想使用 shell 来实现这一点。
我想从粗体字段中提取字符串“db2”,这个对应“tags”字段,这个字段用/tab分隔,不能使用固定位置因为它的大小可变。
实际文件摘录是:呈现2条记录,以时间戳开头。
[Jeff 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/