从文件中提取特定模式 [英] To extract specific pattern from file
本文介绍了从文件中提取特定模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有下面的文件 file.txt,我需要在其中提取模式.
I am having below file file.txt where i need to extract pattern.
CREATE TABLE `test`(
`id` string COMMENT '',
`age` string COMMENT '',
`city` string COMMENT '')
ROW FORMAT SERDE
'org.apache.hadoop.hive.ql.io.orc.OrcSerde'
WITH SERDEPROPERTIES (
'path'='hdfs://local/')
STORED AS INPUTFORMAT
'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat'
LOCATION
'hdfs://local/'
TBLPROPERTIES (
'COLUMN_STATS_ACCURATE'='false',
'EXTERNAL'='FALSE',
'numFiles'='14',
'numRows'='-1',
'rawDataSize'='-1',
'spark.sql.sources.provider'='orc',
'spark.sql.sources.schema.numParts'='9',
'spark.sql.sources.schema.part.8'='....":{}}]}',
'totalSize'='12',
'transient_lastDdlTime'='12')
我会在下面要求
CREATE TABLE `test`(
`id` string COMMENT '',
`age` string COMMENT '',
`city` string COMMENT '')
在Unix中如何实现?
How is it possible to achieve in Unix ?
推荐答案
如果你知道表中的列数,你可以使用 grep.在这种有 3 列的情况下使用这个:
If you know number of columns in table, you can use grep. In this case with 3 columns use this:
grep -A 3 'CREATE TABLE' file.txt
其中 -A 后的 3 是匹配后将包含到输出中的行数.
Where 3 after -A is number of lines after match which will be included to output.
如果您不知道列数,请使用 awk.
If you do not know number of columns use awk.
这篇关于从文件中提取特定模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文