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

How to pass cat output as a wget url parameter?

I have a small file containing just a number located at /mnt/1wire/342342342/temperature I need to create a cron to wget http://myserver.com/myurl?temp= (and here goes that line) I believe I should use somewhat cat /myfile | wget…
puff
  • 11
  • 3
-1
votes
1 answer

linux cat: No such file or directory

I have a peculiar problem in Linux2.4, C and using gcc. There is a small program to retrieve information from a file using cat & grep cmd. #define tmpFile "/tmp/cli_tmp_file.txt" #define MAX_CMD 50 void getRange() { char cmd[MAX_CMD+1]; …
UserM
  • 190
  • 2
  • 19
-1
votes
2 answers

using cat in R to create a formatted R script

I want to read an R file or script, modify the name of the external data file being read and export the modified R code into a new R file or script. Other than the name of the data file being read (and the name of the new R file) I want the two R…
Mark Miller
  • 12,483
  • 23
  • 78
  • 132
-1
votes
1 answer

How to extract bits from binary executable

For a research project, I need to hash the "executable footprint" of an application. I don't have an expansive knowledge-base on this particular area. I've tried cat bash for example, and stdout prints gobbledygook. How can I read an executable as…
Dolphiniac
  • 1,632
  • 1
  • 9
  • 9
-1
votes
1 answer

Seems like wrong shell script: cat

I have a problem using this start.sh script. When I type ./start.sh, it doesn't work. I mean, it makes no errors but it does nothing. When I open this file using VIM (I really want to upload the image, but I can't because I registered this site…
-1
votes
2 answers

Over-riding Standard Input and Output in C

I wrote this code for overriding the cat command in Ubuntu. The following three formats for cat instruction are working properly but rest are not working. Working ones: ./catf > File.txt ./catf < File.txt Not Working: ./catf File1.txt >…
Alfred
  • 1,543
  • 7
  • 33
  • 45
-1
votes
3 answers

Bash Script to validate the existence of User Name in /etc/passwd

I want to create a Bash Script to check the existence of a user name in /etc/passwd. If it exists then add it to users.txt file. I am not really good at UNIX programming, so I hope somebody can help me. while(get to the end of /etc/passwd){ …
DmitryK
  • 1,333
  • 1
  • 11
  • 18
-2
votes
3 answers

Merge files, reverse order and replace text

I have a data file (*.js) per day with the following content: m[mi++]="26.03.23 23:55:00|0;0;0;2720;0;0;0|488;0;3270" m[mi++]="26.03.23 23:50:00|0;0;0;2720;0;0;0|1360;0;3220" m[mi++]="26.03.23 23:45:00|0;0;0;2720;0;0;0|192;0;3110" ... I would like…
SNWBRDR
  • 11
  • 3
-2
votes
1 answer

Bash Redirects That I Don't Understand

I have a variable called payload that points to a file and I have this line that is completely baffling me. Can anyone interpret this for me? cat > $payload <&0 Above this line I also have other cryptic messages that I don't understand either. …
Sachin Kainth
  • 45,256
  • 81
  • 201
  • 304
-2
votes
1 answer

When Using 'cat ~/my_password.txt | docker login --username foo --password-stdin', getting errors: 'cat: No file exists' and 'Cannot perform login'

I'm trying to use --password-stdin and followed the directions here: https://docs.docker.com/engine/reference/commandline/login/ I've looked all over the internet and tried many different things, but nothing is working. Here is a snapshot of my…
-2
votes
1 answer

How to parse file as an argument using cat command

I need to parse the file as an argument to my C code by using cat: cat filename | ./code -n 10 So that it works the same way as: ./code filename -n 10 Or is there any way to read the file directly through the cat command by using read syscall? I…
-2
votes
2 answers

Bash print file contents between two strings

a b s start text more text end even more text end I want to print the content between start and first end that follows the start (start is always unique). I also want to print between which lines the text had been printed, in this example between…
GeoCap
  • 505
  • 5
  • 15
-2
votes
1 answer

It is not possible to find a positional parameter that accepts the 'kernel.bin'

command: cat bootsect.bin kernel.bin > os-image.bin Error: Get-Content : It is not possible to find a positional parameter that accepts the 'kernel.bin' argument. No linha:1 caractere:1 + cat bootsect.bin kernel.bin > os-image.bin +…
-2
votes
1 answer

How remove equal rows having n columns in Linux

I have a file (df.txt) with 3045 rows and 900.000 columns, but 145 repeated rows, thus: 1234 1111122233330000000000003333311122222............................ 1235678 00000000000000000000000111111122222............................ 4567 …
Johanna Ramirez
  • 161
  • 1
  • 9
-2
votes
1 answer

Unix command for below file

I have a CSV file like below 05032020 Col1|col2|col3|col4|col5 Infosys Tcs Wipro Accenture Deloitte I want record count by skipping date and Header columns O/p: Record count 5 with including line numbers cat …