cat is a Unix utility used for concatenating files.

learn more… | top users | synonyms

0
votes
1answer
23 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
45 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
77 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
67 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
431 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
41 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
84 views

splitting a CSV and keeping the header without intermediate files

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
173 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
85 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
428 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
68 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
105 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
107 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 ...
2
votes
1answer
46 views

top not showing the memory usage of cat

I wanted to generate some waste file of 50 GB. so i wrote this eightnoteight@mr:~/ while true; do > cat txt >> tmp > cat tmp >> txt > done and when i ran top,watch to observe. ...
0
votes
2answers
40 views

Are `less textfile | col` and `cat textfile` the same?

Do less textfile | col and cat textfile accomplish the same thing? I wonder if man mysql | col -b > textfile and man mysql > textfile do the same?
11
votes
2answers
225 views

Why does cat x >> x loop?

The following bash commands go into an infinte loop: $ echo hi > x $ cat x >> x I can guess that cat continues to read from x after it has started writing to stdout. What is confusing, ...
5
votes
6answers
941 views

Command to output file content to stdout?

I know cat can do this, but its main purpose is to concatenate rather than just displaying the content. I also know about less and more, but I'm looking for something simple (not a pager) that just ...
1
vote
1answer
233 views

What does this `cat` statement do?

I'm new to Linux and trying to figure out what this statement in a Bash file does. I think it combines stdout, stderr and output it to the file $log is pointing to and append the multiline string to ...
0
votes
1answer
26 views

find file read it and search for specific identifier

I'm trying to find out in what files some specific identifiers are being used. I know the file's name and know the identifier, therefore I use the following command to achieve my desired result: find ...
1
vote
1answer
67 views

cat combining not all file formats - but which ones?

In GNU⁄Linux, combining files with cat works in miraculous ways – at least for me: cat part_* > /destination/file.xyz with the same file format for BOTH source and target file(s) ...
1
vote
0answers
33 views

Edit a command? [duplicate]

I'm using many basic commands of unix/linux. In Mac OS X Mavericks, I type cat for a file, but output was faulty. In example, content of the file named bar: foo bar Then: ...
-1
votes
3answers
916 views

cat /dev/null emptied my log file but size did not change

I'm quite new to Unix. Using Solaris 10 I faced the below issue. There is a large log file with size 9.5G. I tried to empty the file using the below command. # cat /dev/null file_log.txt By doing ...
4
votes
2answers
933 views

How to pipe a remote file to stdout over scp or sftp?

Using ssh, it is easy to print the contents of a file using ssh host 'cat file.txt' When ssh is disabled, and only SFTP is enabled, running the previous command gives the following error: ...
3
votes
1answer
67 views

Does cat never read from terminal?

Chapter 43. Redirecting Input and Output of Unix Power Tools, Third Edition has to say this about cat command: Standard input (stdin) normally comes from your keyboard. Many programs ignore ...
4
votes
2answers
133 views

(cp is to cat AS mv is to ?) mv multiple files into one file instead of cat * rm *

For everything in this question pretend the system only has one disk and filesystem. (we are not writing to different partitions, disks or filesystems) I am working on a project that cats very large ...
2
votes
2answers
60 views

Backed up over wrong hard drive

I've just written over the wrong hard drive using the command: sudo sh -c 'pv /dev/sdb >/dev/sdc' How do I go about undoing this? I was creating the first even backup of the drive, and I backed ...
0
votes
2answers
34 views

concatenate .out files

Can I combined multiple .out files with the cat command in bash or csh? Additionally I want only the header of first file to be concatenated and I was thinking of using the tail function for that. ...
3
votes
1answer
61 views

How to set default tabs only for cat?

I prefer to set tabs 4 however this may have some side effects, such as for example ls out put may look not properly aligned. How might I configure the terminal / cat to use four spaces for tabs for ...
3
votes
2answers
425 views

How to interleave the lines of two or more files?

I have tried to get the 2 files output in a single file. I have tried below command: cat file1 file2 but here file2 data is appending to file1. What I need is file1 1st line followed by file2 ...
13
votes
2answers
1k views

How do I “cat and follow” a file?

A file is being sequentially downloaded by wget. If I start unpacking it with cat myfile.tar.bz2 | tar -xj, it may unpack correctly or fail with "Unexpected EOF", depending on what is faster. How to ...
2
votes
2answers
1k views

continuous reading from named pipe (cat or tail -f)

I have configured rsyslog to log certain log events to /dev/xconsole: *.*;cron.!=info;mail.!=info |/dev/xconsole /dev/xconsole is a named pipe (fifo). If I want to see what is being logged, I ...
0
votes
2answers
901 views

Passing a variable to a bash script that uses 'EOF' and considers the variable a literal [closed]

in this script i end up with "$1" being saved to the /test file. #!/bin/bash cat > /test << 'EOF' $1 EOF the truth is.. i need to keep 'EOF' as 'EOF' because my argument($1) contains ...
2
votes
2answers
182 views

“cat” command: how to automatically escape everything that might be a violation?

If you copy the contents of httpd.conf and then paste it into a cat command.. such as this one.. #!/bin/bash cat > /test << EOF pasted here.. EOF you run into this error: -bash: ...
4
votes
6answers
2k views

How to tell “cat” command to not hang on when there is no path provided?

I am simply trying to get a bash script to return the content of a text file. #!/bin/bash cat $1 the problem is.. when the path to a file is not fed to this bash script... how will it even close ...
-2
votes
3answers
269 views

Replace $ with £ using cat Command

I have file test_output_archive.svd with some Dollar signs ($). I have generated a shell script Replace_dollar_pound.sh with cat command to replace dollar symbol with Pound (£) script is working on ...
0
votes
3answers
104 views

How to fork a “cat” command?

This is my bash script. #!/bin/bash oo="`cat /etc/httpd/conf/httpd.conf`"; cat > /a.txt << EOF $oo EOF it simply reads /etc/httpd/conf/httpd.conf and writes it to /a.txt, the problem has ...
15
votes
5answers
775 views

Is it possible to make zcat output text even if it's uncompressed? [duplicate]

The problem is I have some database dumps which are either compressed or in plain text. There is no difference in file extension etc. Using zcat on uncompressed files produces an error instead of the ...
11
votes
5answers
2k views

Difference between cat and '>' to zero out a file

Are these two commands any different on how they go about zero-ing out files? Is the latter a shorter way of doing the former? What is happening behind the scenes? Both $ cat /dev/null > ...
1
vote
1answer
151 views

Difference between cat * and cat * >>

To merge multiple files in a dir I have tried: cat * myfile.log but this seems to just merge line and line and is thus very slow So using instead: cat * >> bigfile merges the files much ...
0
votes
1answer
89 views

removing the last line of a file not working? [duplicate]

I have this TXT file that is created by a bash script and at the end I want to remove the last line of that file that is an empty one. head --lines=-1 r3.txt > r4.txt sed '$d' r3.txt > r4.txt ...
0
votes
0answers
151 views

cat echoes to serial port

Connecting my Windows PC to a Linux system (Wheezy) via the serial port (RS232) basically works except one problem when sending a message from the the PC terminal the Linux system. The reception of ...
4
votes
1answer
294 views

How can I get less or cat to use color in the output from .cat of my .bashrc, similar to vi 'ing it?

When I vi my .bashrc file it is colorized, i.e. but when I cat or less the file I get all white, i.e. How can I get cat (and less) to have color? cat does have color for my ruby .rb files but ...
4
votes
2answers
158 views

Spliting `File` and `directory name with space' via shell script

I've got a file called Files.txt having following content: TestApp/Resources/Supporting Files/main.m TestApp/Resources/Supporting Files/AppDelegate.h TestApp/Resources/Supporting Files/AppDelegate.m ...
8
votes
4answers
3k views

Why does “cat ttyUSB0” not produce output?

I connected an infrared receiver to a USB port ... (the last line of dmesg tells device file) $ dmesg [10496.596063] usb 7-2: new full-speed USB device number 2 using uhci_hcd [10496.751112] usb 7-2: ...
2
votes
2answers
2k views

Why using cat on binary files messed up the terminal and how?

If I understand correctly the cat manual: concatenate files and print on the standard output cat will take files as argument and print them on standard output. What I don't get is if I use the ...
10
votes
2answers
5k views

Fastest way to concatenate files

I've got 10k+ files totaling over 20GB that I need to concatenate into one file. Is there a faster way than cat input_file* >> out ? The preferred way would be a bash command, Python is ...
2
votes
1answer
87 views

< and << in UNIX /Linux

What is the option <<and < are used in linux for??? For example cat << abc.txt I know its a stupid question, but i was not able to search it on google as i did not know what ...
1
vote
1answer
211 views

Cat and Less give different output

I executed the following command # top > /home/user/top_output.txt Nothing Happened for a while and then i pressed Ctrl+C. When i checked the file that was created, it had the contents in it. So ...
5
votes
2answers
1k views

How can I get the tac command on OS X?

I like to use tac to reverse the output of cat. However, it's not available in the Mavericks terminal. I tried to find it on MacPorts and again it's not available. Can anyone please show me how to get ...
1
vote
2answers
1k views

How can I concatenate all files in a directory together in one command line operation? [duplicate]

I have 1000 csv files in a directory. I would like to concatenate them all together in order. They are named img_size_1.csv to approx img_size_1000.csv This answer is close but assumes a list file. ...