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
3 answers

Piping filename from standard input in linux into c++

I want to be able to write a line in a terminal (as below) that takes a text file in the same directory and inputs its name into an executable file. cat fileName | executable I want to be able to read the fileName into c++ code. I already have a…
Onpetcow
  • 33
  • 5
0
votes
3 answers

Concatenation of huge number of selective files from a directory in Shell

I have more than 50000 files in a directory such as file1.txt, file2.txt, ....., file50000.txt. I would like to concatenate of some files whose file numbers are listed in the following text file (need.txt). need.txt 1 4 35 45 71 . . . I tried…
Kay
  • 1,957
  • 2
  • 24
  • 46
0
votes
0 answers

provide interactive parameters for

I have a shell command "/var/tmp/shcommand" which interactively accepts 3 parameters(press enter after each parameter).Will the following commands work? cat <
vaj oja
  • 1,151
  • 2
  • 16
  • 47
0
votes
1 answer

how to read a value from filename and insert/replace it in the file?

I have to run many python script which differ just with one parameter. I name them as runv1.py, runv2.py, runv20.py. I have the original script, say runv1.py. Then I make all copies that I need by cat runv1.py | tee runv{2..20..1}.py So I have…
physiker
  • 889
  • 3
  • 16
  • 30
0
votes
1 answer

How to stack up the files datablock by datablock?

I have three files in a folder. File A have 700 lines, made up of 100 data blocks. Each datablock have 5 lines. First line has the total number of lines per datablock, 2nd line is empty, and 3~7th line are data. 5 AA 356djs 225gsd 1245gr BB …
exsonic01
  • 615
  • 7
  • 27
0
votes
1 answer

Access a file with a $variable-unix

I am trying to access a file that has a variable in its name (i.e. file_n: file_1, file_2, etc). I am trying to access it with cat $file_$n But this doesn't work. Any ideas?
0
votes
2 answers

How to create a file containing TAB with cat?

I wanted to create a file in my bash script using cat containing a TAB Char. However I couldn't manage to get it working. Here my tests: Using plain tab: cat >file.txt <
Leon Kasko
  • 117
  • 2
  • 7
0
votes
2 answers

Extract the hole .xsl content from a .str file to an xsl/txt file

I am doing some forensics learning, and got a .str file that has an entire .xsl file: I need to extract all that .xsl file from the .str file. I have used something like: cat pc1.str | grep "" > talk.txt The problem is that I get almost all…
Sergio Calderon
  • 837
  • 1
  • 13
  • 32
0
votes
1 answer

Command line tool to get binary data as String in Windows like Cat?

So I have program that transforms data by piping the string into stdin like so. cat input.mp3 | myexe except I want this commandline tool to run on Windows. type input.mp3 | myexe.exe and cat and type provide different inputs because of how…
Skylion
  • 2,696
  • 26
  • 50
0
votes
1 answer

how can i merge multiple files in linux?

I have 30 different length files, each of which start with 1 and ends by around 2000. I can join them by using "cat" options in unix but I want to join those files sequentially. Here is the picture of files: File:1 1 T= 295. E=…
Sushanta
  • 1
  • 1
0
votes
2 answers

Correctly interpret newline characters

I have a file which I need to parse, word by word, and make changes to only certain words. My bash script works in everything but retaining newline characters. I have constructed a minimum example as follows: #!/bin/bash # contents of…
drjrm3
  • 4,474
  • 10
  • 53
  • 91
0
votes
2 answers

Scala Process for Linux is stuck

I'm trying to use Scala Process in order to concate two files and send the result to a new file. The code works fine, but when i remove the permissions to the folder, it seems to be stuck. Here is the code: val copyCommand = Seq("bash", "-c",…
user3725190
  • 343
  • 4
  • 14
0
votes
2 answers

How to merge multiple files into single file in given directories

I want to write a shell script to merge contents of multiple files in a given directories. DIR1 contains sample1.txt sample2.txt sample1.txt contents :---this is sample1 file sample2.txt contents :---this is sample2 file DIR2 contains…
ashwini
  • 531
  • 5
  • 13
  • 28
0
votes
0 answers

How do I debug my program with GDB when using piped input?

I'm using GDB to debug a program I've written and I'm having issues with GDB syntax. The portion of the program I'm testing requires input piped from file (via cat command), so altering the arguments to remove the pipe and read directly from file…
andrewlef
  • 1
  • 1
0
votes
1 answer

Concatenate file weight less than the sum of the files

I have done these commands to concatenate the files into one file: $ ls -1 | wc -l 16916 $ ls -1 *.txt | wc -l 16916 $ ls -lh | head -1 total 93M $ cat *.txt > ../nectar_3.txt $ ls -lh ../nectar_3.txt -rw-r--r-- 1 llopis llopis 52M May 25 16:03…
llrs
  • 3,308
  • 35
  • 68