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

How to print a specific range of lines and enumerate them with sed or awk

I would like to know how to print specific range of lines using sed or awk and enumerate them like something like this HORSE CAT DOG LION MOUSE MONKEY SNAKE PANDA WOLF TIGER so that the output of the line 4-9 looks like this 1. LION 2. MOUSE 3.…
Marcus
  • 13
  • 3
-2
votes
2 answers

BASH: Find newlines in between text and replace with two newlines

I am looking to programmatically edit the newlines of .txt files. The desired behavior is that any single newline in between lines of text will become two newlines. edit (clarification by @kaan): Lines separated by one newline should be separated…
Grady Woodruff
  • 143
  • 2
  • 11
-2
votes
1 answer

With cat command create a file which is a merge of 2 files(linux)

What I'm trying to do: With cat command create a file named Merge which is the merge of test.txt and Copy(in a different directory than test.txt) Both test.txt and Copy contain the same content: reglib test.txt So what I expect…
Daniel_Kamel
  • 610
  • 8
  • 29
-2
votes
1 answer

bash scripting cat and echo

I new in bash scripting and i bug with this: tab=( "^[A-Z]\{4,\}[0-9]\{4,\}" ) for (( i=0; i<=$(( ${#tab[*]} - 1 )); i++ )) do tmp+=" grep -v \"${tab[i]}\" |" done # for remove the last | …
-2
votes
1 answer

"Index out of range" while reading contents from a file through cat PYTHON

I am trying to get input from a file, through cat command, into a python file. My python version is 3.5. The code looks like this. with open(sys.argv[1]) as f: while True: if f.readline()== '': break line =…
sid0972
  • 141
  • 1
  • 4
  • 13
-2
votes
1 answer

Linux command Cat dont file archive but archive in folder

When I try to cat in one file, for exemple cert.pem I receive ab error: No such file or directory
Lucas Resende
  • 582
  • 5
  • 14
-2
votes
4 answers

Sort files in directory and then printing the content

I need to write a script to sort filenames by the character that comes after the first "0" in the name. All the file names contain at least one 0. Then the script should print the content of each file by that order. I know i need to use sort and…
user10336290
-2
votes
1 answer

How can I set a variable to be the output of cat command?

I have a file named "myout" in my current directory. I wish to set the variable x to be the output of that line: cat myout | cut -d" " -f1 | cut -d"/" -f1 I searched all over the site and couldn't find an answer, any help would be appreciated!
Tamir
  • 3
  • 2
-2
votes
3 answers

Combining two cat statements into a single cat statement within bash

I want to combine 2 different cat statements into a single cat statement cat /dir1/file1.cfg | grep -q "linux" cat /dir1/file2.cfg | grep -q "linux" is there an OR operation that can be used here to do the grep -q "linux" on 2 files?
meallhour
  • 13,921
  • 21
  • 60
  • 117
-2
votes
1 answer

Why cat command not working in script

I have the following script and it has an error. I am trying to merge all the files into one large file. From the command line the cat commant works fine and the content is printed to the redirected file. From script it is working sometime but not…
Dr. Mian
  • 3,334
  • 10
  • 45
  • 69
-2
votes
1 answer

How to append a file(copied from aws s3 bucket) to another file in Linux,

I want to copy file from S3 bucket and I need to append the file to another file. I want to done in single command. aws s3 cp s3://sample/test.txt /home/user/test.txt this command is overwriting the existing file. If i use "cat >>" it was giving…
Srinivas R
  • 335
  • 1
  • 3
  • 8
-2
votes
2 answers

How can i cat all txt files to terminal using python?

I want to cat txt files from a folder and cat results should be shown in terminal (Obviously). I have tried using listdir() it but it doesn't work. Required some help!
-2
votes
2 answers

How to read each file in a folder using cat (recursively) and store it in a file?

I have a file with 9k PDF documents. I wish to read the source code (not content) of each of them using cat and store them in a separate text file with the same name as that of the PDF. For example cat 030.pdf > 030.txt I want to do this for all…
BlackSwan
  • 275
  • 3
  • 12
-2
votes
1 answer

Android Studio - logcat

Can someone tell me what is wrong with my app it crashes on statr . Here is the LogCat: Process: com.moneyegg.bdpsoft.makemonepaypal, PID: 3358 …
-2
votes
1 answer

awk, sed, shell: How to use data from one file to another

I have two files with the following format: File1.txt 1 apple 1.056 ref 15 File2.txt 2 apple unknown ref unknown1 How can I have the value for apple (1.056) from File1.txt be used in place of the what's written for File2.txt? I would like…
user7649922
  • 513
  • 1
  • 4
  • 9
1 2 3
99
100