Cut first and last line field

saniboy

I'm using grep to pull specific lines from multiple files and I'm trying to use cut to get the first and last field then use sort to get unique lines.

I can cut the first or last field using:

command output | rev | cut -f1 | rev
command output | cut -d(delimiter) -f1

I'm failing to find any documentation or previous questions that allow me to cut both fields in one shot with the number of fields in between being inconsistent.

The output before cut looks like:

object garble garble #
object garble garble #
object garble garble garble #
object garble garble #

And the output I need is:

object #
object #
object #
object #

Note that the value of 'garble' is inconsistent as well, they represent notes made.

heemayl

This is an easy job for awk, get the first and last field:

awk '{print $1, $NF}' file.txt

To preserve the field separator:

awk 'BEGIN{OFS=FS} {print $1, $NF}' file.txt

Este artigo é coletado da Internet.

Se houver alguma infração, entre em [email protected] Delete.

editar em
0

deixe-me dizer algumas palavras

0comentários
loginDepois de participar da revisão

Artigos relacionados

Why I can not search the first word or last word in a Solr field?

Remove everything after the last occurrence of selected character in the first line

How can I skip the first and the last line of a file in PHP

Remove connecting line between first and last record of ggplot

How to remove spaces, and show only the first character from a second field with cut and unix tools?

IONIC V1: Form Keydown Enter Fired on last field but not on the first field inside Device

How to pick first occurence of a field and last occurence of another field at the same time in a SAS dataset?

Regex: How to insert text before the first line and after the last line of file

remove the first duplicate line based on a matched field and keep the second matched line

ffmpeg cut first 5 seconds

How do I print the first line of a file after sorting without the last value in powershell?

Skip first and last line from a pipe delimited file with 26 columns and make it to dataframe using scala

How to remove the last CR char with `cut`

how can I sort a field form an Endnote Export File format where the Line contains GRAZ in the address as first line?

First, last bin in IntervalIndex

First and Last function in sqlite

Remove first and last backslash?

Replacing the SPACE at first and last

UITextView last line is not shown

Crystal Reports: Display date range (month, first day of month, year to month, last day, year) based on field value

minimum line height to ensure text is not cut off

How to cut off int at the end of a line

Field and text in the same line

Proc sql last not empty field

Readline is skipping the first line

Laravel Eloquent - equivalente a first () for last?

Ruby Ranges first and last issue

Masking First and Last Name String with *

Javascript equivalente a Jquerys: first /: last

TOP lista

  1. 1

    R Shiny: use HTML em funções (como textInput, checkboxGroupInput)

  2. 2

    O Chromium e o Firefox exibem as cores de maneira diferente e não sei qual deles está fazendo certo

  3. 3

    Como assinar digitalmente um documento PDF com assinatura e texto visíveis usando Java

  4. 4

    R Folheto. Dados de pontos de grupo em células para resumir muitos pontos de dados

  5. 5

    Gerenciar recurso shake de Windows Aero com barra de título personalizado

  6. 6

    Como obter dados API adequados para o aplicativo angular?

  7. 7

    UITextView não está exibindo texto longo

  8. 8

    Por que meus intervalos de confiança de 95% da minha regressão multivariada estão sendo plotados como uma linha de loess?

  9. 9

    Acessando relatório de campanhas na AdMob usando a API do Adsense

  10. 10

    Usando o plug-in Platform.js do Google

  11. 11

    Como posso modificar esse algoritmo de linha de visada para aceitar raios que passam pelos cantos?

  12. 12

    Dependência circular de diálogo personalizado

  13. 13

    Coloque uma caixa de texto HTML em uma imagem em uma posição fixa para site para desktop e celular

  14. 14

    iOS: como adicionar sombra projetada e sombra de traço no UIView?

  15. 15

    Como usar a caixa de diálogo de seleção de nomes com VBA para enviar e-mail para mais de um destinatário?

  16. 16

    Tabela CSS: barra de rolagem para a primeira coluna e largura automática para a coluna restante

  17. 17

    How to create dynamic navigation menu select from database using Codeigniter?

  18. 18

    Converter valores de linha SQL em colunas

  19. 19

    ChartJS, várias linhas no rótulo do gráfico de barras

  20. 20

    用@StyleableRes注释的getStyledAttributes。禁止警告

  21. 21

    não é possível adicionar dependência para com.google.android.gms.tasks.OnSuccessListener

quentelabel

Arquivo