【问题标题】:To extract specific pattern from file从文件中提取特定模式
【发布时间】:2018-01-18 04:21:13
【问题描述】:

我有以下文件 file.txt 我需要提取模式。

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中怎么可能实现?

【问题讨论】:

标签: shell scripting


【解决方案1】:

如果你知道表格的列数,你可以使用grep。在这种有 3 列的情况下,请使用:

grep -A 3 'CREATE TABLE' file.txt

-A 后面的 3 是匹配后的行数,将包含在输出中。

如果您不知道列数,请使用 awk。

【讨论】:

猜你喜欢
  • 2013-05-27
  • 2020-06-02
  • 2014-08-05
  • 1970-01-01
  • 1970-01-01
  • 2016-06-22
  • 1970-01-01
  • 2018-11-20
  • 1970-01-01
相关资源
最近更新 更多