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

cat command: unexpected output

I tried the following command $cat < text > text where text is a non-empty file. There was no output to stdout and the file text became blank. I expected cat command to read the file text and output the contents to the same file. However when I…
Ajax
  • 1,689
  • 4
  • 20
  • 29
0
votes
2 answers

How to detect and separate concatenated files?

I am trying to find a method to separate two files that have been concatenated together using copy /b file1+file2 file3. I know the mime type and file type of at least one of the two files.
Gerbal
  • 661
  • 6
  • 8
0
votes
1 answer

View content of all files modified on certain date

I would like to print out the content of files in one directory. I want to see only the content of files that have been modified today. I tried this approach: ls -lt | grep '6. Dez' | cat Since it does not work, I am wondering what would be the…
aldorado
  • 4,394
  • 10
  • 35
  • 46
0
votes
1 answer

cat command: stdin redirection not working when used along with a file

I don't understand, while following cat command doesn't display contents of both file1.txt and file2.txt cat file1.txt < file2.txt It's displaying contents of file1.txt, but not the contents of file2.txt while the following commands work as…
neon
  • 462
  • 6
  • 17
0
votes
3 answers

Unix cat function (cat * > merged.txt) in Python?

Is there a way to use the cat function from Unix in Python or something similar once a directory has been established ? I want to merge files_1-3 together into merged.txt I would usually just find the directory in Unix and then run cat * >…
O.rka
  • 29,847
  • 68
  • 194
  • 309
0
votes
3 answers

How to extract a string, number, or word from a line or database and save it to a variable? (script in bash)

My question can be split in 2. First I have a data file (file.dat) that looks like: Parameter stuff number 1 (1029847) word index 2 (01293487), bla bla Parameter stuff number 3 (134123) word index 4 (02983457), bla bla Parameter stuff number 2…
Leo
  • 35
  • 5
0
votes
7 answers

Shell Script to show multiple line after match

I got this file root: admin = true SYSTEM = "compat" registry = files account_locked = false su = true sugroups = system,security,sec_grp daemon: admin = true expires = 0101000070 account_locked = true bin: …
0
votes
1 answer

check if there is a string data in specific port on bash script

I want to make a program with bash script, that can check if there is a string data from specific port in my machine. Can you help me with this programming? thanks... *sorry for my bad english example: *my machine port 7090, and if there is a string…
user2745521
  • 1
  • 1
  • 2
  • 2
0
votes
1 answer

Trying to output all possible combinations of joining two files

I have a folder of 24 different files that all have the same tab-separated format: This is an example: zinc-n with-iodide-n 8.0430 X zinc-n with-amount-of-supplement-n 12.7774 X zinc-n with-value-of-horizon-n 14.5585 X zirconium-n as-valence-n…
owwoow14
  • 1,694
  • 8
  • 28
  • 43
0
votes
3 answers

How do I combine two files without overwriting any data in python?

I need to concatenate two files, one which contains a single number and the other which contains at least two rows of data. I have tried shutil.copyfile(file2,file1) and subprocess.call("cat " + file2 + " >> " + file1, shell=True), both things give…
0
votes
3 answers

Include first line with AWK and set output based on filename

cat /path/to/file1 /path/to/file2 | awk '{if ($3~/^TCF/ || $3~/^GLI/) print $0;}' > /path/to/test1.txt Do you know how to: Include the first row in file1 in the test1.txt output? And, is it possible to include if TCF and GLI came from file1 or…
user2862862
  • 111
  • 1
  • 1
  • 10
0
votes
3 answers

awk '/^/' empty output (complete command inside)

cat /path/to/file | awk '{if ('/^TCF/' || '/^FSTL/' ) print $0;}' > /path/to/output.txt Hi! This produces an empty output, however it does work on a "textedit document", but not this "Plain text document". Other than that, its no different, only…
user2862862
  • 111
  • 1
  • 1
  • 10
0
votes
2 answers

Struggling with spaces in file.txt with cat

Im trying to create a list of file-paths from a file but I don't seem to be able to get around the spaces in the file paths. # Show current series list PS3="Type a number or 'q' to quit: " # Create a list of files to display …
0
votes
3 answers

Linux: How can i extract information from the files's name?

I have some files(.txt), the name…
0
votes
2 answers

joining text file with cat and bash

so, i have two text file containing title1 title2 stored in title.txt and data1 data2 stored in data.txt and i'd like to join it with cat, so it gonna look like this title1 | data1 title2 | data2 but, the regular cat title.txt data.txt > out.txt…
user1072976
  • 63
  • 2
  • 8