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

C concatenate options to CAT program?

As the title suggests I have to make a program to emulate the CAT commands, so far I have got basic input and output working however I need now include options such as -n..... while((rd = getchar()) != EOF){ if(putchar(rd) == EOF){ …
0
votes
1 answer

Bash Merge 2 files conditionally

I'm trying to merge the second field of the csv with all the id's in the diff file. codes.csv has 2 fields: ID,Description. I keep getting an error on the second cat. cat: codes.cvs: No such file or directory. The file does exist and I'm running…
ExceptionLimeCat
  • 6,191
  • 6
  • 44
  • 77
0
votes
1 answer

Need help mixing criteria in extended globbing

I have a directory with the following files: foo.bar.1.txt foo.bar.2.txt foo.bar.1.out foo.bar.2.out bar.1.txt bar.2.txt bar.1.out bar.2.out I have two goals: Primary: In a script, I'd like to cat bar.2.out (but not foo.bar.2.out) but the "bar"…
William Everett
  • 751
  • 1
  • 8
  • 18
0
votes
1 answer

How to order by slug in wordpress without $args

Im the admin of a website built in wordpress, builded by someone else. I know only the basics, I made a few changes here and there but now I hit a wall. What Im trying to do is order some categories by slug. Here is the code that calls categories.…
0
votes
2 answers

Not reading from stdin properly

I'm trying to mimic the behavior of the unix utility cat, but when I call a command of the form: cat file1 - file2 - file3 My program will output file1 correctly, then read in from stdin, then when I press EOF, it will print file 2 then file 3,…
nope
  • 223
  • 4
  • 15
0
votes
1 answer

Write a shell script with find, cat and if

I'm doing a scipt to search a log file with an age and compare who has a string of text within the log, if it is correct to proceed to make a function, but not effected. I appreciate any advice or help #!/bin/bash file= find /AUX/backup/log/ -iname…
user1980835
  • 11
  • 1
  • 2
0
votes
1 answer

Print files in one line in cat/column environment

I need to print a list of files in one line in cat/column environment. The problem is -- it prints in multiple lines: #!/bin/bash Files=`ls ~/` echo $Files # prints in one line as I want. But I have to do it inside cat/column: # prints files in…
Adobe
  • 12,967
  • 10
  • 85
  • 126
0
votes
2 answers

CommandLine Arguments not working C

I am trying to pass File1.txt ">" File2.txt as terminal arguments to my program in order to override the cat command. But for some reason, the program is not working. Although the argc is 4 in above defined case but still the condition in the…
Alfred
  • 1,543
  • 7
  • 33
  • 45
0
votes
1 answer

I can't create files

I'm logged into an android device via ADB wireless and I'm root. I'm in /sys/devices/platform/musb_hdrc/ trying to modify a file called mode. When I pipe something into the file, it returns without error, but the file is unmodified. And when I…
themirror
  • 9,963
  • 7
  • 46
  • 79
0
votes
1 answer

C /sys/class/pwm init within a program

So you can see in this link that you have a pwm /sys/class/pwm/. So I am currently putting the right data into the appropriate files and things are working well. That is not the issue. The issue is that you need to do a "cat" on the…
napierzaza
  • 439
  • 5
  • 21
0
votes
1 answer

how to redirect `cat` to simulate user input in linux

I began a project. In the instruction, it is written that we could test our program with this command line : cat test.txt > test.py But I have no output. As I understood, it is supposed to give me an output. test.txt file looks like…
Malik Fassi
  • 488
  • 1
  • 10
  • 25
0
votes
3 answers

Bash script error with cat and if

I'm learning bash but now I'm having a lot of trouble making this script work: #!/bin/bash A="0" B="0" C="0" D="0" E="0" F="0" G="0" while true; do sleep 1 BATTERY='cat battery.txt' if [["$BATTERY" -le 100] && ["$BATTERY" -gt 85] && [$A -eq…
HumiD
  • 35
  • 1
  • 1
  • 5
0
votes
1 answer

cat a file to remote system using Expect

I'm trying to write my first expect script which will push new language to a remote file. This is what I have so far that isn't really working: #!/usr/bin/expect set fid1 [open ./hosts.list r] set hosts [read -nonewline $fid1] close $fid1 set…
theillien
  • 1,189
  • 3
  • 19
  • 33
0
votes
2 answers

Linux: cat /dev/video0 into a not growing buffer

I want to cat a /dev/video0 device output (Transport Stream is the kind of output) into a temporary ring buffer. In fact i do not want that the file/buffer is growing over the time. So the purpose is to have a file (buffer, Fifo, whatever) to be…
Fox
  • 35
  • 1
  • 5
0
votes
1 answer

Runtime.exec - fine for 'echo' 'but not for cat...

I'm having a problem calling some simple command line functions with r.exec - for some reason, given a file X the command 'echo full/path/to/X' works fine (both in the display and with 'p.exitValue()==0', but 'cat full/path/to/X' does not (and has…
Joe
  • 4,367
  • 7
  • 33
  • 52