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

cat files with filenames in .tsv

I have file names provided in a tab separated file. Ex: file1 file2 file3 file4 file5 file6 file7 file8 file9 file10 file11 file12 ......and so on. I need to be able to do: cat file1 file2 file3 > newfile1 cat file4 file5 > newfile2 cat file5…
st.ph.n
  • 549
  • 2
  • 5
  • 19
0
votes
1 answer

Use cat to combine mp3 files based on filename

I have a large number of downloaded radio programs that consist of 4 mp3 files each. The files are named like so: Show Name - Nov 28 2011 - Hour 1.mp3 Show Name - Nov 28 2011 - Hour 2.mp3 Show Name - Nov 28 2011 - Hour 3.mp3 Show Name - Nov 28 2011…
cainram
  • 11
  • 3
0
votes
1 answer

Unix open file from line X or first 100 lines after Z found

I have a 2GB text file and I want to read every line 100 lines after a certain string is found example: string: 'epicvar (string) ="5"' string was found on line 5000 so I want to read the file from 5000 to 5100 then the string was also found on…
0
votes
2 answers

input file is output file error

I'm trying to run the command find . -name "*.csv" | xargs -I{} cat '{}' > Everything2.csv and I get back: cat: ./Everything2.csv: input file is output file What does this mean?
user3736201
  • 99
  • 2
  • 6
0
votes
1 answer

Cat Content after a specific line in log file

I would like to cat the contents of a file that follows and includes the target line. 2014-06-23 11:01:01,001 dog 2014-06-23 12:01:01,001 cat 2014-06-23 13:01:01,001 elephant 2014-06-23 14:01:01,001 bird 2014-06-23 15:01:01,001 rabbit …
JSolano
  • 51
  • 1
  • 1
  • 8
0
votes
2 answers

How to use cut and awk commands to extract text input in a tabular format?

I have file input.txt as below: filename: test1.v BUG: bug 102 is fixed by some user IO_CHANGE: there is no io_change for this version FEATURE: no feature added filename: test2.v BUG: bug 103 is fixed by some user also bug 105 is fixed IO_CHANGE:…
0
votes
1 answer

Some strange output on my command in linux shell

I've written the following in the command: $ cat /bin/ls > blah $ cat blah blah blah > bbb $ chmod u+x bbb $ ./bbb And it printed all the file names in the current working directory. My question is why? and why not 3 times?
Mickey
  • 480
  • 4
  • 13
0
votes
3 answers

Using sort -M to sort by month

I have a file months.txt with the following text: JAN, MAR, DEC, FEB, JUN, APR In bash I write the following line of code: cat months.txt | sort -M I assumed that this would output the text file, sorted by month. However the output is not sorted.…
Jakeimo
  • 71
  • 6
0
votes
2 answers

MPlayer screenlog output

my friend is creating mplayer server on Raspberry PI and is currently trying to check screenlog for current time. The problem starts with getting the last line. Doesn't matter if we use tail, awk, read or anything else, the console output is always …
SEJBR
  • 348
  • 8
  • 15
0
votes
1 answer

Piping with Cat

I cant seem to know that failing here. I intend Reading a file from a csv file to a Postgres DB. I have this cat Master.csv.2014-06-04-13-18-52 | tr \" \ | psql -U dev test_db This is the CSV file that I'm…
dev
  • 382
  • 1
  • 3
  • 17
0
votes
2 answers

difference between 'cat -A' in bash and 'set list' in vim

File is bidd.nus.edu.sg/group/TTD/filedownload.asp?file=flatfiles/drug-disease_TTD2013.txt When I use cat -A drug-disease_TTD2013.txt it shows ^M$ in the end of each line. In vim, set list and it shows only $ without ^M. sed 's/\r//'…
Zhilong Jia
  • 2,329
  • 1
  • 22
  • 34
0
votes
2 answers

Cat multiple sources to multiple targets

I have several servers that log some data into .csv files and send the files to a NAS. I need to add each .csv file to a corresponding aggregate logfile. Googling has turned up nothing relevant (perhaps I'm not using the right searchstring?) The way…
Mausy5043
  • 906
  • 2
  • 17
  • 39
0
votes
2 answers

In UNIX, is it possible to "cat" a file over http?

Here is what I want to do: cat https://raw.githubusercontent.com/jplew/SyncDB/master/syncdb This gives a "No such file or directory" error, because cat, evidently, cannot grab a remote file over HTTP. Is there another way to accomplish this? The…
JP Lew
  • 4,121
  • 2
  • 32
  • 45
0
votes
2 answers

Apply the same bash script to multiple folders?

I have a simple bash script that takes all .md files of the current folder and merge them into a new file: for f in *.md; do cat "$f"; echo; done > output.txt; It works well. Now I'd like to extend this script to takes a bunch of directory as…
pimpampoum
  • 5,816
  • 6
  • 24
  • 27
0
votes
1 answer

Check My Understanding of cat and Posix Tee

cat < existingInputFile | tee newOutputFile > newOutputFile2 cat command is executed and the result is written in a file names existingInputFile then send the output of existingInputFile to tee after that I am lost... does tee get the…
Ria
  • 447
  • 6
  • 16