Questions tagged [cat]

The cat command is a standard Unix program used to concatenate and display files. The name is from catenate, a synonym of concatenate.

cat - concatenate files and print on the standard output.

The cat command is used for:

  1. Display text file on screen
  2. Read text file
  3. Create a new text file
  4. File concatenation
  5. Modifying file

Example

$ cat -n file #shows the content of a file, including the line-numbers(-n flag)

Concatenating two files into third file:

cat file1 file2 > output_file 

The purpose of cat is to concatenate (or catenate) files. If it is only one file, concatenating it with nothing at all is a waste of time, and costs you a process." This is also referred to as "cat abuse". Nevertheless the following usage is common:

cat filename | command arg1 arg2 argn
cat -- "$file" | grep -- "$pattern"
cat -- "$file" | less

can instead be written as:

grep -- "$pattern" "$file"
less "$file"

A common interactive use of cat for a single file is to output the content of a file to standard output. If the output is piped or redirected, cat is unnecessary.

Without two named files, the use of cat has no significant benefits.

Useful links

1519 questions
-1
votes
2 answers

Make all files ( that are in diffrent folders ) in one file

I tried to do specific thing using for loops and I need you help. I have different folders that have different names like GCF_A1 GCF_C4 GCF_R3... and so on. Every folder there's lots of files that have different names like this GCF444444 GCF00001RR…
Reda
  • 449
  • 1
  • 4
  • 17
-1
votes
1 answer

Makefile executes $(shell command) unordered

I am having an issue with my Makefile: At the begining of the Makefile, a file is created. I wanna retrieve the content of that created file by using the "cat command". I need to use the $(shell cat) execution because I have to retrive it inside…
user2607702
  • 41
  • 1
  • 6
-1
votes
1 answer

Call bash random function inside cat file lines

The goal is to use the bash function inside the cat lines that creates an html file. Must be easy knowing the way, but this does not "compile" while writing at Sublime: #!/usr/bin/env bash function create_file_with_random_numbers { …
Dieglock
  • 169
  • 1
  • 16
-1
votes
1 answer

linux merge multiple files, but skip lines starting with '#'

I have a list of 10 files that I want to merge into one file. file1.txt file2.txt ... file10.txt I normally do this with cat cat file*.txt > merged_file.txt However, I don't want the lines starting with '#' to be included in the merged_file.txt.…
user1987607
  • 2,057
  • 6
  • 26
  • 53
-1
votes
2 answers

Reading file backward while using variable from first line

I want to read a file back ward while using a variable present in the first line (here: 2636). My file: nx_ 2355 ny_ 2636 0.000000 0.000000 0.000000 1.000000 68.000000 0.428139 2.000000 68.000000 0.939878 3.000000 67.000000 0.757181 4.000000…
Argent
  • 33
  • 6
-1
votes
1 answer

cat EOF issues with indentation

NOTE: If anyone feel this question has been answered before please paste your answer below otherwise please don't interfere with people trying to help someone who needs help. Thanks I am not sure why it is such an hassle trying to cat content to…
uberrebu
  • 3,597
  • 9
  • 38
  • 73
-1
votes
2 answers

How to directly append columns of one file to another file

Requirement: Only grep/cut/join/cat/regex/for/while. I am a beginner at shell utilities. I have fileA and fileB containing equal number of rows. I want to append columns of fileB into fileA. I am trying this (cat fileA && cat fileB) > fileC. But it…
user10143594
  • 59
  • 1
  • 1
  • 8
-1
votes
3 answers

Correct syntax and usage of `cat` command?

(This question is a follow-up on this comment, in an answer about git hooks) I'm far too unskilled in bash (so far) to understand fully the remark and how to act accordingly. More specifically, I've been advised to avoid using bash command cat this…
Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
-1
votes
1 answer

Linux cat command

$ cat a.txt > a.txt Why does this above command make a.txt empty? Base on my understanding, cat a.txt is going to shows the a.txt, then write the output to a.txt. It should do nothing, but why a.txt become empty? Can someone please explain…
qi xu
  • 3
  • 2
-1
votes
2 answers

Merging files in folder with same file name except one character

I have filenames like the…
Jack Arnestad
  • 1,845
  • 13
  • 26
-1
votes
2 answers

how to merge files based on the name pattern

/myfiles/sandboxserver_local.tar.gz.part-aa /myfiles/sandboxserver_local.tar.gz.part-ab /myfiles/sandboxserver_local.tar.gz.part-ac /myfiles/sandboxserver_shared.tar.gz.part-aa /myfiles/sandboxserver_shared.tar.gz.part-ab /myfiles/sandboxserver_shar…
sporty
  • 51
  • 3
-1
votes
2 answers

Print specific string in a line after matched word in bash

Situation There is a file called test that consists on the following text: this is the first line version=1.2.3.4 this is the third line How can i print via bash only: 1.2.3.4 Note: I want always to print until end of line what is after…
Mr ASD
  • 103
  • 1
  • 1
  • 8
-1
votes
2 answers

using WHILE DO GREP

I am trying to make this work but no output. What I'm trying to do here is from a txt file which has multiple names will be grep and export the ip address which match to the username. and will continue to loop for each line read and export to…
-1
votes
1 answer

linux cat files excluding the ones beginning with a certain prefix

I am trying to cat all png files in a directory and pipe them to the ffmpeg command: cat *.png | ffmpeg it works but I now wanto to exclude from the list all png file beginning with the prefix 'legend_'. How do I achieve this? I know that using ls…
Dino
  • 1,307
  • 2
  • 16
  • 47
-1
votes
1 answer

Get current line of a file that is piped to a command

My goal is to figure out a PIN password for a daemon listening at port 30002. So I created a dictionary called pinlist and i pipe it to nc (netcat) localhost 30002 This is the command: cat pinlist | nc localhost 30002 It works, I get in, but the…
MyWays
  • 113
  • 1
  • 7