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

Match a line and cat multiple files into one file

I have a file with 3 columns and 4426 row some thing like this file1 : DAEQUEG00000025 FP3SLUG00002140 FOMPING00001058 DAEQUEG00001923 FP3SLUG00002391 FOMPING00000186 DAEQUEG00000047 FP3SLUG00002116 FOMPING00001081 DAEQUEG00000321…
kapr0001
  • 1
  • 1
-2
votes
1 answer

Can't cat to a file in /usr/bin

I ran the following command, hoping to be able to paste a file's contents into it. sudo cat > /usr/bin/sasquatch And keep getting the following error, even after changing the file permissions with sudo. bash: /usr/bin/sasquatch: Permission…
baranskistad
  • 2,176
  • 1
  • 21
  • 42
-2
votes
2 answers

What's the difference between cat and ypcat?

What's the difference between: cat /etc/passwd and ypcat passwd ? What is ypcat exactly? Why do I get this: ypcat: can't get local yp domain: Local domain name not set when running ypcat passwd.
Kate
  • 45
  • 4
  • 8
-2
votes
1 answer

Understand tar and ssh backup

Hello everybody i'm copying a folder from a computer to another usign tar and SSH, with the next command, but i don´t understand how cat -> are working. Someone could help me to understand it well? ssh systemmanager@127.233.117.43 “tar czvpPf -…
-2
votes
2 answers

How to modify the cat command

So I'm trying to show the contents of a text file with every occurrence of a particular word that is highlighted. I don't want to use grep as that only shows the sentences with that word in. I want to use the cat command.
-2
votes
1 answer

merge files with similar substring

I want to merge paired files that share similar start of the filesname. The output should be a unique name found in the corresponding input files. I am not sure how do do this, however, cat would do somehow.…
user2300940
  • 2,355
  • 1
  • 22
  • 35
-2
votes
2 answers

Why won't cat work inside my bash-script?

I want to be able to display the content of my command-list document but whenever I do it just prints out "./commands.txt" but if I try the same thing outside of my script it works just fine. This is my code: helpFile="./commands.txt" if […
NanoCoder
  • 35
  • 1
  • 6
-2
votes
3 answers

New to using Linux

Using a pipe, sort a directory listing (i.e. list contents of directory and sort)… then pipe this output into cat and redirect the output into a file named “exercise5.7.txt”. I sorted the list contents of the directory. Just need help with how to…
-2
votes
2 answers

write output to a specific file in C

My program executes with two arguments (put in argv) like below: $ myProgram input output How do I redirect all printf(..) to the output file? I saw some suggestion about using fflush(stdout) but I haven't used it before. Could anyone please show…
Toan Le
  • 412
  • 1
  • 6
  • 17
-2
votes
1 answer

Grep and cat cause Terminal to hangup. Terminal displays process going but nothing happens

Learning command line as basis for further web development learning. Using a Mac whenever I try to use GREP or CAT, Terminal hangs up. Once I enter the process it displays in the top border, but nothing happens. What am I doing wrong?
-2
votes
1 answer

I want to create a function in UNIX C to display the content of a file

I want to create a kind of agenda of championships and when a user logs in into my "database" he has to have access for visualising the championships details. These kind of details i keep in a file. How should my function look like ? I think I…
-2
votes
1 answer

Why is inbuf = xmalloc (insize + page_size - 1)?

I'm reading cat source code, but I dont understand the following piece of code insize = MAX (insize, outsize); inbuf = xmalloc (insize + page_size - 1); Why is the buffer created with a size of insize + page_size -1?
yuwenbao
  • 13
  • 1
-2
votes
3 answers

Incorrect AWK command

I had a ~300mb text file full of asterisk calls which needs to be sent to a customer although cannot include specific information, The only information i would like to extract is as follow; Everything between the asterisks *NUMBER#NUMBER,sip-out* I…
-3
votes
1 answer

Why does cat < /dev/ttyS0 send output to ttyS0?

When I use cat < /dev/ttyS0 and data is received, it doesn't display on the terminal that I typed the command into but instead gets sent back to to ttyS0 where it came from. How can I make it not do that?
user1318499
  • 1,327
  • 11
  • 33
-3
votes
1 answer

Split html file looking for text and join the two output files

I want to split an html file into 2 parts (outfile1.html and outfile2.html). The first should reach a first line containing II (the variable 'linea' should indicate the line number) followed by another line with LARGE (XL). After a…
1 2 3
99
100