我想使用Linux命令行从文件复制一列以成为另一个文件的第一列

时间:2019-06-25 08:25:01

标签: linux

我想从文件中复制一列,使其成为另一个包含许多列的文件中的第一列。我该如何使用命令行呢?

文件1为

2  5
3  5
3  5
-  -
-  -

文件2为

1 2  5
2 3  5
2 3  5
- -  -
- -  -

我希望fil3为

Signatures

1 个答案:

答案 0 :(得分:0)

这是graphql-js的完美工作:

const { SchemaDirectiveVisitor, gql } = require("apollo-server")
const { defaultFieldResolver, GraphQLString, GraphQLList } = require("graphql")

const schema = gql`
  directive @myDirective(
    fields: [String]
  ) on FIELD_DEFINITION | FIELD

  type mainType { 
    anotherType: [AnotherType]
  }

  type AnotherType { 
    nestedType: [Object] @myDirective
  }
`

class MyDirective extends SchemaDirectiveVisitor {
  visitFieldDefinition(field) {
    const { resolve = defaultFieldResolver } = field
    field.args.push({
      name: "fields",
      type: GraphQLList(GraphQLString)
    })

    field.resolve = async (source, { fields, otherArgs }, context, info) => {
      const results = resolve.call(this, source, otherArgs, context, info)

      return results.filter(result =>
        fields.every(field => result.value !== field)
      )
    }
  }
}

paste使用空格分隔两行;这是必需的,因为$ paste -d' ' file1 file2 1 2 5 2 3 5 2 3 5 - - - - - - 默认使用标签。