cat is a Unix utility used for concatenating files.

learn more… | top users | synonyms

5
votes
2answers
283 views

Why does `cat` seem to iterate over JSON arrays?

I'm puzzled by this behaviour of cat when trying to output a heredoc containing JSON in bash 3.2: input: $ cat <(cat <<EOF > {"x":[{"a":1,"b":2}]} > EOF) output: {"x":["a":1]} ...
1
vote
0answers
19 views

overlayfs root filesystem, cannot read /etc/mtab

I'm doing the following: mkdir /tmp/upper /tmp/work mount -t overlay overlay -o lowerdir=/,upperdir=/tmp/upper,workdir=/tmp/work / ls -l /etc/mtab > lrwxrwxrwx 1 root root 19 27. Feb 09:16 ...
8
votes
1answer
72 views

OS X, bash: less works on open file descriptors, cat doesn't

In a bash script I'm working on (which has to run on Ubuntu and OS X), I need to redirect the output of hundreds of commands to a file. Rather than appending &>... to all of them, I simply do ...
1
vote
1answer
29 views

Adding a crontab - syntax

crontab -l | { cat; echo "0 0 * * * /path/to/cron/job"; } | crontab - I took this line from the net, to add a new cron job. It works well and good. I got the doubts, 1) Why do we need the curly ...
28
votes
6answers
3k views

Is 'cat' a shell built-in or an external program?

When I use the type command to find out if cat is a shell built-in or an external program I get the output below: -$ type cat cat is hashed (/bin/cat) -$ Does this mean that cat is an external ...
4
votes
2answers
141 views

Cat file1 into file2 after specific pattern match

I have file1 & file2, I want to cat file1 into file2 after match of 22 pattern. Can I do it with cat or I need to go for awk or sed file1 aa bb cc file2 11 22 33 44 Resultant file2 11 ...
1
vote
1answer
55 views

Merge multiple HTML files in reverse order?

I have multiple HTML files for this book. I am trying to add them in opposite order. I've tried: cat *.html >> merge.html I've tried to use tac on the list of downloaded files by time to no ...
0
votes
3answers
95 views

Concat 1000 files within a directory [closed]

I know we can concat files by cat file [file] [[file] ...] > joined-file. I have directory which contains lots of files. I want to concat all of them. I want to concat 1000 files irrespective of ...
6
votes
2answers
732 views

bash - why does \x0d\x20 erase the line

This is the view from gedit editor: and the view from vim editor: I then try to grep it, it did grep successfully if i put Log instead of Tog, but the output is corrupted: [xiaobai@xiaobai grep]$ ...
3
votes
2answers
56 views

When does cat finish reading from a pipe?

Given the following code, why does cat only print the contents of the pipe after I've typed \n or CTRL+D? What are the conditions for cat to actually print what it read? #include <stdio.h> ...
0
votes
4answers
115 views

What the equivalent of “grep | cut” using sed or awk?

Say I had a config file /etc/emails.conf email1 = user@dinkum.dorg email2 = user@winkum.worg email3 = user@stinkum.storg and I wanted to get email2 I could do a: grep email2 /etc/emails.conf | ...
0
votes
1answer
25 views

How to execute several lines into a .txt

I am using SSH; In a folder I have the next files: -rwxrwxr-x 1 german german 48 Apr 29 10:45 prueba.txt -rwxrwxr-x 1 german german 23 Apr 29 10:43 script1.sh -rwxrwxr-x 1 german german 23 Apr ...
0
votes
3answers
46 views

Find the row and append to the bottom of the file

I have a big file with some record which will be having different values than others. Actual data file: 000000106500000000000129201300000U1E4600000060000+00000020400+00000002532+000000 ...
1
vote
2answers
100 views

cat < file.txt Who is the responsible of reading the file?

cat < file.txt Who is the responsible of reading the file ? Is the shell reads the open and read the file then write its content to the standard input of the command ?
2
votes
1answer
54 views

Printing from a FIFO pipe without interfering?

I have a couple of C programs sending messages back and forth through FIFO named pipes in Unix, and I want to see what's going through the pipes using an external program. The problem is that if I use ...
0
votes
1answer
53 views

How to terminate cat command within a shell script

I wrote a shell script that uses cat and tr commands to generate a file. My shell script looks like #!/bin/bash printf "generating random file > plaintext \n" cat -v | tr "a-z" "b-y" < ...
2
votes
2answers
94 views

cat command in shell does not terminate on receving EOT through serial port

I have shell/perl script which kicks off cat commands to receive incoming serial data from n external device. The external device is designed to send to send a EOT character when it's done ...
3
votes
4answers
349 views

How to cat two heredocs? [duplicate]

When cat is given two heredocs, it only outputs the second one. $ cat <<HERE > adsf > qwer > HERE adsf qwer $ cat <<HERE <<ALT > qwer > asdf > HERE > zxcv > ...
2
votes
0answers
132 views

cat /dev/ttyS0 Input/output error

I created infrared receiver as in LIRC manual (http://www.lirc.org/receivers.html). And tested it on windows using program called Terminal. When I switched on RTS pin DCD pin was also switched on ...
0
votes
1answer
52 views

What is the logic behind the expression cat > foo << “wordofchoice” [duplicate]

I know the > and >> operators, > puts something into a file by deleting the old content, >> appends something onto the end of the file's content. When I only use cat > foo I am able to write ...
3
votes
2answers
222 views

Meaning of `cat /dev/null > file`

In a document created by a former coworker there is this command: cat /dev/null > /var/spool/mail/root It says next to it that it will clean out mailbox. Can someone please explain how/why ...
1
vote
3answers
209 views

A sort of reversed cat [closed]

I've two documents that are the result of SQL Queries. For exemple i've my Doc1.lst that is : John1 0 Julien 10 Jules3 0 Julie 30 On this Doc1.lst, I used sed to have only ...
1
vote
1answer
49 views

What happens when I cat a non-text file?

When I run cat on a file that isn't just text it returns a large amount of characters (many of which look like this ���). What is this data?
4
votes
3answers
237 views

How to read dash files

How can I read a dash file from the terminal other than delimiting it with ./ For example to read a - file we can read it by cat ./-file_name Q: Is there an alternative way to achieve the same ...
1
vote
1answer
29 views

file (vdi) increase (at double) size after split and then cat operation

I'd splitted a vdi file with 7 gigabytes and then joined with cat command. The file works normally on VBox, but get 14 gigabytes after be re-joined. The exact operation was: $ split -- bytes=2000M ...
2
votes
1answer
90 views

attempting to put dynamic input data in a variable via cat method

I'm attempting to write a bash script that should be able to collect data from ttyS0 and put in a variable. I need to talk with a device on the serial line, that is a module able to receive AT ...
-2
votes
1answer
56 views

Understanding of a Batch

I need your help to check if my understanding of those lines are correct. As a rookie in Unix, I work step by step. if [ $? -ne 0 ]; then I didn't find any correct explanations about the -ne but I ...
0
votes
3answers
61 views

Reuse output from command 1 in command 2 using a pipe

I've got a command in linux which returns a list of numbers. Now I need this numbers to form a directory path and cat the file located at that path. For example: myCommand returns: 1 10 30 40 And ...
4
votes
2answers
148 views

Characters visible in vi, but not in cat.

I have a 300 lines file with ^@ character between each characters in the file. (I cannot post the entire contents for security reasons, so I am pasting only the first line) [mercury@app01 ftp_logs]$ ...
0
votes
1answer
881 views

How to assign the cat output of a bash script to a variable in another script

I have a bash script that produces a cat output when it takes an argument. I also have another bash script that executes the first bash script with an an argument that I want to produce cat outputs ...
3
votes
1answer
178 views

Mac OS X combine cp and cat to sequentially copy and rename files in list

I am using a MacBook Pro OS X 2013 model. I have a list of filenames in a text file named list.txt separated by line breaks list.txt exactly like this, but this list is going to be long e.jpeg ...
0
votes
1answer
63 views

How could I include a variable in a here document?

I am trying to use a user-defined global variable in a cat <<eof>> filename situation, but it's not working. I found what I want in simple cat << eof examples on this forum, which ...
0
votes
3answers
371 views

How to concatenate a variable number of csv, removing their header rows?

I have a directory with several hundred csv files whose filenames start with two digits {01..84}. Several hundred >> 84, so obviously some filenames start with the same prefix. I wish to concatenate ...
2
votes
3answers
121 views

Multiple arguments using xargs.

I know xargs can take many arguments like so. xargs -n5 -I{} echo {} but how do I put the arguments in a particular location I want do something like. xargs -n5 -I{} curl ...
1
vote
2answers
116 views

Stdin Input Behavior Between “cat” and “less”

When I issue cat, the terminal hangs waiting for stdin input. However, when less is issued, I get Missing filename ("less --help" for help). It is known that both less and cat accepts stdin input. ...
12
votes
2answers
1k views

Ctrl+D for ending terminal line input

If I do $cat > file.txt text<Ctrl+D><Ctrl+D> Question1: If I don't press enter, why do I have to press Ctrl+D twice? If I do $cat > file.txt pa bam pshhh<Ctrl+Z> [2]+ ...
101
votes
7answers
12k views

How to kill a runaway cat?

Many times I accidentally run the cat command on files that have contents up to few thousand lines. I try to kill the cat command with Ctrl+ C or Ctrl+Z, but both only take effect after the total ...
0
votes
1answer
393 views

Command that prints file contents given filename on stdin

I have a command that produces some output part of which is actually a file name containing the full output data. I want to extract the file name (which I trivially do with cut) and then pass it to ...
0
votes
5answers
64 views

Is there a way to do a “full file buffering” inside a chain of piped commands?

Very often I do simple operations on a file, for example: cat file1.txt|sed -r 's/^ *//' to remove spaces at the beginning of the line. If I want to overwrite the file, the only way I know is: cat ...
2
votes
3answers
189 views

How to sort filenames with spaces in them and concatenate the files?

I have the misfortune of dealing with filenames that contain spaces. I want to concatenate files of which filenames contain spaces. I also want to sort the filenames numerically. Obviously the ...
3
votes
2answers
373 views

Less resource hungry alternative for piping `cat` into gzip for huge files

I have some files of which some are very large (like several GB), which I need to concatenate to one big file and then zip it, so something like this: cat file1 file2 file3 file4 | gzip > ...
3
votes
6answers
3k views

get first X characters from the cat command?

I have a text file I'm outputting to a variable in my shell script. I only need the first 50 characters however. I've tried using cat ${filename} cut -c1-50 but I'm getting far more than the first ...
0
votes
2answers
76 views

Cannot merge files using cat [duplicate]

I tried to open a lot of files (10,000+) with cat and them merging them into one like this: cat * > ~/Desktop/lol.xml But it returned this error: -bash: /bin/cat: Argument list too long This ...
2
votes
1answer
555 views

splitting a CSV and keeping the header without intermediate files [closed]

I am trying to split a dozen 100MB+ csv files into managable smaller files for a curl post. I have managed to do it but with a lot of temporary files and IO. It's taking an eternity. I am hoping ...
3
votes
1answer
572 views

grep not working in a for loop over a list

I have some log files. And I have a list of user ids. My log files are in a particular format log-yyyy-mm-dd e.g. log-2014-09-30 I am trying to search each userId in the log file. This is what I am ...
0
votes
1answer
178 views

reading file using for, while - behavior

Consider the below scenario 2 vms - 192.168.229.131, 192.168.229.132 Both the vms has it's ip as 192.168.229.151 & 192.168.229.152 in it's /etc/hosts file Say there are around 50 vms like i ...
3
votes
2answers
3k views

How to concatenate two files in a new one and sort the output in one line

I have two files with some names in them, when I ran cat file1 file2 | sort, the terminal shows the names sorted alphabetically, but when I run cat file1 file2 > file3 | sort I don't see the sorted ...
2
votes
2answers
103 views

Joining files with cat confusion

If I do the following commands: $ cat picture.jpg > copy1.jpg and $ cat -v picture.jpg > copy2.jpg copy1.jpg is a perfect copy of picture.jpg, but copy2.jpg is a lot bigger than ...
0
votes
2answers
602 views

How to combine gunzipped fastq files?

How can I combine gzipped fastq files? I tried this for read 1 and read 2 zcat file_1.fastq.gz file_2.fastq.gz | gzip > combined.fastq.gz but it is giving me unequal number of reads. Why? Is ...
1
vote
2answers
336 views

Concatenate file contents AND names

I've been writing for many months. The files I create are dated files named like 2011-06-13.markdown with daily content. I've decided I want to have all the writing in one file instead but I'd like ...