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

Errors Integrating SED into a Bash Loop

I'm having an issue with a bash script I've written. The command works until the SED, and I'm not really sure what I've done incorrectly. HAL is the variable in the text file that I'm trying to replace. Any ideas? for i in $( cat LIST.txt) do sed…
George
  • 179
  • 1
  • 11
0
votes
2 answers

echo -e cat: argument line too long

I have bash script that would merge a huge list of text files and filter it. However I'll encounter 'argument line too long' error due to the huge list. echo -e "`cat $dir/*.txt`" | sed '/^$/d' | grep -v "\-\-\-" | sed '/
Potential Coder
  • 91
  • 3
  • 11
0
votes
3 answers

How do I get a specific line of a file using 'cat' command?

I have a text file with a lot of mda5 hashes. I need to get only the hash of my file as output. I've tried cat mda5hashes.txt | grep manual12.pdf, but I have this promt: manual12 917NJvfNj6uY237fjzmso38djr7s How can I get only the hash as…
Joshua Salazar
  • 205
  • 4
  • 14
0
votes
2 answers

Why does sort -u give different output from sort filename | uniq -u?

I am getting two different results for the following commands. Want to know the difference between those commands. I want to list unique lines (remove duplicates)in a file. To sort it out, I used following commands. sort -u filename and sort…
Hideandseek
  • 271
  • 1
  • 4
  • 17
0
votes
0 answers

How to combine several file parts (Blobs) to the original file after ajax upload with unix cat command?

I created an uploader script which can upload large files because it splits it into blobs. But I figured out that using PHP's fopen and fwrite won't work for putting the parts back together again (maybe a memory thing). I figured out that there is a…
user2718671
  • 2,866
  • 9
  • 49
  • 86
0
votes
3 answers

Please help me in this nested for loop unix

for i in `ls -l`; do for j in `ls -l /abc`; do cat $j | grep $i;done;done; I want to search for each filename in pwd with files in abc directory. Please help me in this.
0
votes
2 answers

Cat command with a csv file

I have a file called "polls.csv" that I have to use the cat command to return a certain part of. Each line of the file looks like this: Utah,5,27,64,4,Sep 13,,,,,,,5,American Res. Group Here is an example of the cat output:…
John Avena
  • 3
  • 1
  • 1
  • 3
0
votes
1 answer

BASH script more smart with cat

I have multiple files in multiple folders [tiagocastro@cascudo clean_reads]$ ls 11 13 14 16 17 18 3 4 5 6 8 9 and I want to make a tiny bash script to concatenate these files inside : 11]$ ls FCC4UE9ACXX-HUMcqqTAAFRAAPEI-206_L6_1.fq …
Tiago Bruno
  • 413
  • 1
  • 3
  • 17
0
votes
3 answers

unix shell cat a >> a doesn't work

I would like copy the contents of a file twice on terminal, but I don't generates same files, so I type cat a >> a and this job doesn't stop, I kill the job and open file a and found contents of a file a have many row... I know cat a > b ; cat a >>…
crazyeyes
  • 53
  • 5
0
votes
0 answers

Controlled reorganisation of a 3D matrix

This is a noob question I guess, but I want to reshape a 3D matrix in a way that the planes of the 3rd dimension are arranged consecutively on the 1st dimension. The idea is that given a matrix A(720x360x120) I can reshape it into a 86400x360…
0
votes
1 answer

merging big text files together

I am merging many files (~1 gig each) into one file but the merged file is incomplete. when concatenating b to a, b gets concatenated somewhere in the middle rather than end. The command I am running are: for f in $x/*/y/*.fastq; do …
Ananta
  • 3,671
  • 3
  • 22
  • 26
0
votes
2 answers

Adding text to a bunch of files

I needed to append some text to a bunch of files in a directory, so I thought I'd be clever and try something like this: find . -name "*.txt" -exec cat source >> {} \; Which did not work, of course, because the redirect gets picked up by the shell…
lbutlr
  • 414
  • 6
  • 18
0
votes
3 answers

How can I return the entire contents of a split line based on a search?

I posted previously about a small script that I'm working on. I eventually figured out that problem. Now I'm running into a different one. Hopefully you can help. Some setup: I have a short list stored as a markdown file. |One Hundred Years of…
a--clam
  • 3
  • 6
0
votes
4 answers

Outputting the contents of files with an extra line break in between each

I have two files with no line break at the end of the file. So when I call "cat file1 file2", the last line of file1 and the first line of file2 share a line. I need a command that will output the files correctly. I can't change the files.
mattalxndr
  • 9,143
  • 8
  • 56
  • 87
0
votes
1 answer

Inf2Cat Error 22.9.12 - INF cannot be copied to %Windir%

I am making a driver official for Windows 7 as it it unsigned and the process to disable things to make the unsigned driver work is much more hassle then to actually sign the driver. Well, in order to sign the driver, first I need to make the…
user3412975
  • 45
  • 1
  • 5