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

cat using relative paths on mac

I am trying to cat 4 files one directory down to a new file, also one directory down: cat ./dira/file.txt ./dirb/file.txt ./dirc/file.txt ./dird/file.txt > ./dire/file.txt I can get this to work from the Terminal, but not in the following: for i in…
Benjamin
  • 11,560
  • 13
  • 70
  • 119
0
votes
2 answers

bash: how to merge files containing digits at certain position

I want to merge all files, which have one or two digits at certain position. Basically I want to match numbers from 1-22. I write in bash: cat chr[0-9][0-9]{0,}_from6_new_mono.txt >all_autosomes_from6_new_mono.txt I get this error: cat:…
Perlnika
  • 4,796
  • 8
  • 36
  • 47
0
votes
2 answers

cat a file value in plsql

I am just wondering is there any way that we can print the values of a file in plsql thing is: I select 5 columns from a table and one of the column is a path/file. I want to print the contents of the file I know its complex but will be good if…
Kannan Lg
  • 911
  • 4
  • 11
  • 21
0
votes
1 answer

Why Is This Crashing? Android AdView Problems?

I am trying to setup ad in my game but I am having a problem. It seems to be crashing. I have included the logcat below and it has something to do with the ad it seems. 06-07 18:49:54.594: E/dalvikvm(308): Could not find class…
Greg Froning
  • 213
  • 1
  • 4
  • 16
0
votes
1 answer

Bash script send enter key or prevent cat hang

I am currently running a Minecraft server in a screen session with this command: (tail -f /path/to/fifo & cat) | java -Xmx2048M -jar minecraft_server.jar nogui You can shutdown a minecraft server by sending 'stop' in the server console. I am using…
Eddy
  • 1
  • 2
0
votes
1 answer

Ubuntu shell script not working

With this script I want to append a line of text to the /etc/hosts file. The script seems not to be working. What is wrong? su cd /etc cat /home/rugile/file >> hosts And /home/rugile/file looks like this: 127.0.0.1 domain.com
eksponente
  • 49
  • 2
  • 9
0
votes
4 answers

Cat command does not merge files in script

I am not sure what I am doing wrong in following situation - I want to merge multiple files into one, but I want to merge a lot of them, so I want to use something like this: *input file* that contains lines file1.txt >> mergedfiles1.txt file2.txt…
opplatek
  • 23
  • 3
0
votes
1 answer

Concurrent UART Output with Line Buffered

I have 4 UART devices and I want to watch their output concurrently. I use the following script to do this job: # first kill the cat process from last run killall -v cat for i in `seq 0 3`; do cat /dev/crbif0rb0c$(i}ttyS0 | grep .…
Jinghao Shi
  • 1,077
  • 2
  • 10
  • 15
0
votes
1 answer

Bash script comparing curl results with file

So I am writing a script that will curl a site I've written that will return a string. I am using it to compare a value that is saved within a file. I am having trouble getting my conditional statement to return true for matching values. Here is a…
John
  • 57
  • 2
  • 7
0
votes
2 answers

MATLAB 'cat()' function returning different matrix size

If I perform s.device_macs then I get back a <1x3503 cell> so I would expect this as the output of my concatenate but I have 2 things I'm unsure on when I use: a = cat(2,s.device_macs) To concatenate previously I used cat(1,x) but this doesn't work…
Accendi
  • 627
  • 1
  • 7
  • 15
-1
votes
1 answer

Why cat -v prints some characters in strange way?

Why terminal command cat -v prints this text $$$$ $$ $$$$$ ¥ 是我 §«Õϖ‡€ $$$$ $ $$ $$ $ like this? $$$$ $$ $$$$$ Â¥ æM-^X¯æM-^HM-^Q §«ÃM-^UÏM-^VâM-^@¡âM-^B¬ $$$$ $ $$ $$ $ I have a task to implement cat command in C. I've faced with this…
bleschunov
  • 41
  • 6
-1
votes
1 answer

How to subtitute the cat command in a bash file?

I'm working in testing my smt model using different solvers. In this moment I have the file .smt2 which contains the instruction of a model converted in smtlib. I have created a file .sh which implements the linear search in order to test my model…
-1
votes
1 answer

bash script that receives any sequence of nucleotides and print all positions of the T nucleotides

I need to write a bash script that receives any sequence of nucleotides and print all positions of the T nucleotides. I did the following: 'vim nucleotide.sh' inside the script #!/bin/bash $@ cat $@ | while read line;do echo $line | grep -i…
Eman
  • 15
  • 3
-1
votes
1 answer

How to split a file into lines using foreach in linux?

File.txt has numerous lines with paths to different files I want each line of File.txt to become an argument to sed command Ex : File.txt has following lines dir1/sub1/a.txt dir2/sub2/b.txt dir3/sub3/c.txt Need to use sed command on all these files…
-1
votes
4 answers

Renaming variant column

I have a large file with rsIDs in the 2nd field. Some variants are in this format: chr1-97981343:rs55886062-AT Using bash commands, how can I replace these identifiers to just print the rsID (e.g. rs55886062)? Toy data set: 1 rs3918290 110…
Svalf
  • 109
  • 4