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
1 answer

copy file content to target file. After last match of pattern in target file. Content from original filed displays on next line of target file

I have two files, file.1 $ cat file.1 this is the stuff that needs to be copied. and file.2 $ cat file.2 aaaa aaaa aaaa aaaa bbbb bbbb bbbb bbbb cccc cccc cccc cccc dddd dddd dddd dddd I would like to copy the contents of file.1 to file.2…
Antzzz
  • 1
  • 1
0
votes
1 answer

pipeline in script dumps to stdout (or stderr) instead of displaying pv output

I am writing a script for downloading and installing Raspbian to a flash drive. When I run it in the terminal with root access, it winds up cat ing all the output onto the screen (annoying). When I take the command that it is running and run it in…
Jonathan Wheeler
  • 2,539
  • 1
  • 19
  • 29
0
votes
1 answer

print the file output without ^M

I have a file with ^M char in it HTTP/1.1 200 OK^M HOST_SERVICE: FutureTenseContentServer:11.1.1.8.0^M Transfer-Encoding: chunked^M Date: Wed, 20 May 2015 02:00:04 GMT^M Content-Type: text/html; charset=UTF-8^M X-Powered-By: Servlet/2.5…
Ravikanth
  • 353
  • 1
  • 6
  • 17
0
votes
1 answer

Difference between typing a shell command, and save it to a file and using `cat myfile` to execute it?

I have an rsync command that works as expected when I type it directly into a terminal. The command includes several --include='blah' and --exclude='foo' type arguments. However, if I save that command to a one-line file called "myfile" and I try…
n3utrino
  • 1,160
  • 1
  • 8
  • 16
0
votes
0 answers

How to write and then read only one line from serial /dev/ttyACM0

I'm trying to write to my arduino through the serial port: #!/bin/bash exec 3<> /dev/ttyACM0 echo "v" >&3 cat <&3 exec 3>&- The based on the letter it receives it should return the value from one of the sensors. For simplicity I replaced that…
diCoy
  • 79
  • 2
  • 9
0
votes
1 answer

How do I join two files on a newline?

When I run cat 1.txt 2.txt > result.txt, I want result.txt to have a linebreak between the end of the contents of 1.txt and the beginning of the contents of 2.txt. How do I do this?
Username
  • 3,463
  • 11
  • 68
  • 111
0
votes
0 answers

cat > post-receive inside the hooks folder freezes

I'm trying to set up automatic deployment with Git with a VPS. I've created a site.git folder and I'm inside the hooks folder. When I run the next command inside the hooks folder: cat > post-receive The server doesn't do anything, it just…
Bernard R
  • 3
  • 3
0
votes
1 answer

Unable to add silence to end of mp3 using cat

I have a mp3 file with silence, s.mp3, which I'm trying to add to the end of an mp3 using: cat file1.mp3 s.mp3 > file1.mp3 This worked fine for some mp3 files I downloaded from the net but not the files I created myself using lame. I'm on mac os…
Baz
  • 12,713
  • 38
  • 145
  • 268
0
votes
0 answers

Using a text file as input for a binary

I'm trying to test my homework (knapsack problem) and it's getting repetitive entering all these inputs every time I recompile. Here's what I've got: will@will-mint ~/code/byun-sp15 $ g++ knapsack.cpp will@will-mint ~/code/byun-sp15 $ ./a.out Please…
Will
  • 4,299
  • 5
  • 32
  • 50
0
votes
0 answers

Wordpress category search input

I have a search function at the top of my blog however which searchs all posts. I want to add a search function that only searches for posts within a category. Can i use the current search and add this to a page and tell it to display only from…
Justin
  • 1
0
votes
1 answer

Deleting Extended ASCII characters from a .txt file Linux Terminal

I'm trying to generate a list of word frequency from a .txt file, I do not want certain ASCII printable characters and all the Extended ASCII characters to contribute to the word frequency list. Here is my generalized code: cat file.txt | tr -d…
SL3_88
  • 3
  • 2
0
votes
2 answers

Trying to collect output from multiple statments

Is there a way to wrap all of this write (pun intended) no only ``` is in temp.md echo "\`\`\`" && cat temp.txt && echo "\`\`\`" > temp.md
ThomasReggi
  • 55,053
  • 85
  • 237
  • 424
0
votes
0 answers

cat, sort, gzip of 20GB files

I am out of memory to perform all steps individually, therefore I was thinking or doing something like this: cat r_T_H_17.bed r_T_H_stim.bed r_T_mem.bed r_T_naive.bed r_T_reg.bed | sort -k1,1 -k2,2n -k3,3n | bgzip > all_r.bed.gz all files are min…
Alina
  • 2,191
  • 3
  • 33
  • 68
0
votes
0 answers

cat into file deletes the content of the written file

I am trying to write my first bash script. It checks if a USB-to-Seria bridge and an USB-Storage device is connected and then starts writing the incoming data on the /dev/ttyUSB0 into a file on the attached storage device. The problem is this part…
Rush
  • 31
  • 1