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
0
votes
2 answers

Cat redirection auto kill?

I'm trying to do the following : cat > somefile "some text" ; clear; some other program but without having to press <"ctrl + d"> so that line will create the file and then run some other program. I tried echo "some text" > somefile;…
Morki
  • 215
  • 1
  • 3
  • 11
0
votes
2 answers

Concatenate multiple pairs of files

I have 120 pairs of files I would like to concatenate. I have the list of pair of files and the proposed merged file name in a tab delimited file as follows Filelist.txt /filepath/1_first.fasta /filepath/1_second.fasta >…
0
votes
2 answers

filter2D openCV function error

I m using this line with this function but I have an error. filter2D(GaussKernel,conspic1,GaussKernel.depth(),split(GaussKernel,KernelAchrSplit),Point(-1,-1),0,BORDER_DEFAULT); Kernel and conspic1 are Mat object. I suppose I have a problem with the…
Elvio
  • 17
  • 7
0
votes
4 answers

Assign a header to multiple files, Linux

A header file is produced by running the main script and its content changes anytime I run the program . I want to assign the content of header file to other three files as their header. The content of other three files should not change except…
newzad
  • 706
  • 1
  • 14
  • 29
0
votes
3 answers

Insert content of a file to another file on Linux

I have two files. I want to insert the content of the first file(file1) to the second file (file2) between some codes (second file is a script). For example the second file should look like this upcode... #upcode ends here file1 content downcode…
newzad
  • 706
  • 1
  • 14
  • 29
0
votes
1 answer

Hosts file missing on Mac OS X - Xcode Failing to compile code

I've tried to run my first objective-c code in Xcode... Compilation process was successfully, however an error returns " invalid host string: 'localhost' ". After some Googling, I found out and connected the points that it might had something to do…
GuilhermeMesquitaX
  • 177
  • 1
  • 1
  • 8
0
votes
1 answer

How to save a string from a file into a variable in bash

I am trying to make a script that will ask you for a path to several files when you set it up and when you run the actual script, it reads the path from a file that you created earlier. I can make the file, I just need to know how to take that path…
Zachary Alfakir
  • 83
  • 1
  • 11
0
votes
1 answer

Uncompress, edit, compress and concatenate files

I have a bunch of large compressed files that I want to concatenate. Problem is, the don't have newline characters at the end of the uncompressed version, so if I try to just cat them together and work on them compressed, the last line in one file…
GrahamE
  • 5
  • 1
0
votes
1 answer

comparing lines with awk vs while read line

I have two files one with 17k lines and another one with 4k lines. I wanted to compare position 115 to position 125 with each line in the second file and if there is a match, write the entire line from the first file into a new file. I had come up…
user37774
  • 3
  • 1
0
votes
4 answers

Remove a variety of lines in a text file

I've been trying to implement a bash script that reads from wordnet's online database and have been wondering if there is a way to remove a variety text files with one command. Example FileDump: **** Noun **** (n)hello, hullo, hi, howdy,…
user191960
  • 1,941
  • 5
  • 20
  • 24
0
votes
1 answer

Creating a bash file with variables with PHP and phpseclib

I need to create a bash file with PHP using the phpseclib library. This is the code I am using now: $ssh->exec("cat > $sPath$sSavingCode <
Runner
  • 115
  • 2
  • 11
0
votes
3 answers

Combine linux commands into one output

I cat some files into a markdown parser, and want to pre/ap-pend a head/foot-er. Currently, I do it with a few commands, but would like to do it with a one liner. Here is the command I want to add to... cat `find .. -name "*.md" -type f` |…
Billy Moon
  • 57,113
  • 24
  • 136
  • 237
0
votes
1 answer

Unix shell script: Inject text when "text pattern" is found

Say I have two files: - data.txt - report.txt The report contains a text with some "placeholders", example: HPLC results for sample: , elements analyzed: The data file contains a series of "key/value"…
LabJem
  • 3
  • 1
0
votes
1 answer

How does man.cgi deal with cat vs. mdoc man pages?

I want to start a site with a collection of BSD man-pages, similar to man.cgi, but static HTML, and which includes all the stuff from the ports trees, too. I've tried unpacking man/ from all the OpenBSD packages for a recent release, and I've…
cnst
  • 25,870
  • 6
  • 90
  • 122
0
votes
2 answers

Format output of multiple bash commands into columns

What I want to do is simple enough, but I cannot get it done without several commands. This is what it looks like so far. I'd love to be able to do this in one sloppy looking line that just passes all the commands at once. # cat…
gNU.be
  • 1,937
  • 2
  • 10
  • 9