How can I use each line of a file as an input switch in bash?

Eddi

I have a file that contains a list of filenames on each line.

myfile.txt:

somepath/Documents/a.txt
somepath/Documents/b.txt
somepath/Documents/c.txt

This file can contain any number of lines. What I want to do is then run a command that runs cat with each line being an input, such as:

cat <line 1> <line 2> <line 3> new_combination_file.txt

I was looking this up and I think I should be using xargs to do this, but when I looked up examples and the man page, it didn't make sense to me. Can someone help?

Barmar

Use a while read loop to read each line into a variable

while read -r filename
do
    cat "$filename"
done < myfile.txt > new_combination_file.txt

You can also use xargs:

xargs cat < myfile.txt > new_combination_file.txt

However, this won't work if any filenames contain spaces.

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

How can I switch the position of a line with the line after it in a text file using a Scanner?

How can I use File.AppendAllText and add to it a new line?

How can I use switch case statement in bash scripting to perform different operations?

How can I run arbitrary bash scripts on files via Webpack without maintaining loaders for each file type?

How can I delete a specific line from a txt file based on user input?

how can I switch between positions and also switch value of an input with same class name inside them?

How do I separate a each text file line into a separate lists?

How can I switch git branches when there is an untracked file error?

How can I source multiple bash scripts into each others properly?

How can I divide line from input file in two parts and then compare it to the two column data of database table in c#?

How do I read two strings on each line, line by line, from a file in C

How do I loop though a text file, line by line, and append each line to an array?

How can I compare grep line numbers in a conditional statement in bash?

How can I reassign saved file in input file tag ReactJS

Can I perform a 'non-global' grep and capture only the first match found for each line of input?

How can I use to the stream extraction operator to read a file assuming that only the last line will have errors of not containing 3 values

How can I use getopt with command line arguments in Swift 3?

How can I use getopt with command line arguments in Swift 3?

How can I use broadcasting to code my program in one line?

How can I create a new "file type" in the command line?

How can i cast the .nth() line in a file as an integer?

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

Can I use a switch statement without break;?

How can I use a VStack as input for a func in SwiftUI?

How can I use onkeydown outside of an input element?

How can I use user input to name a child in Firebase?

How can I use createImageBitmap with raw data as input rather then an image

How can i use an array to take user input

How can I check if my input file is updated?

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