Questions tagged [cat]

cat is a standard Unix utility used for concatenating files or printing specific file on the standard output.

Filter by
Sorted by
Tagged with
1
vote
2answers
280 views

Why does the cat command only read from the first file descriptor?

From the console, I've created 2 empty files, and I tried to read them simultaneously. $ echo -n '' | tee f1 > f2 $ cat f1 f2 $ cat <(tail -f f1) <(tail -f ./f2) On the other console I've ...
-5
votes
2answers
412 views

How does this `cat` command to txt script file work?

Suppose we have a txt file file.txt with each line is a python script e.g. python a1.py python a2.py python a3.py What does the following command is really doing ? cat file.txt | xargs -n 1 -P $...
0
votes
2answers
539 views

bash - add blank line to heredoc via variable

If I am using this scenario in a script: #!/bin/bash addvline=$(if [ "$1" ]; then echo "$1"; echo; fi) cat << EOF this is the first line $addvline this is the last line EOF if $1 is emty I ...
7
votes
2answers
2k views

Reading a named pipe: tail or cat?

I made a file descriptor using mkfifo fifo As soon as something is written to this pipe, I want to reuse it immediately. Should I use tail -f fifo or while true; do cat fifo; done ? They seem ...
4
votes
3answers
853 views

How to interleave two txt files with alternative number of lines

file1.txt: 1 2 3 4 5 6 file2.txt: A B C D E Desired output in 3 : 1 ratio (file3.txt) 1 2 3 A 4 5 6 B Commands I have tried: sed Rfile2.txt file1.txt >file3.txt paste -d '\n' file1.txt file2....
4
votes
3answers
4k views

merge file text with file name

I have two text files. The first "file1.txt" has content: Apple Orange Banana while the second file "file2.txt" has content: monday tuesday wednesday I want to combine them into one file and its ...
8
votes
4answers
7k views

cat files in specific order based on number in filename

I have files named file.88_0.pdb, file.88_1.pdb, ..., file.88_100.pdb. I want to cat them so that file.88_1.pdb gets pasted after file.88_0.pdb, file.88_2.pdb after file.88_1.pdb, and so on. If I do ...
4
votes
4answers
2k views

echo a file as a single line with \n's

I have a multi line text file that I want to echo out as a single line file where the new lines are shown as \n. Any pointers would be great.
3
votes
0answers
243 views

how to disable keyboard on debian 9 with shortcut?

I want to know if it's possible to configure Debian 9 to dedicate one key on the keyboard to disable the the rest of the keyboard. I'm trying to watch something and my cat keeps walking on the ...
0
votes
2answers
45 views

How to preserve the content of an existing file and concatenate content from another file into it using cat command

For Example we have the following files: $ ls $ test1 test2 random $ cat test1 This is a test file $ cat test2 This is another test file $ cat random This is a random file $ Now I want to preserve ...
2
votes
2answers
6k views

What is the difference in using Ctrl+D and Ctrl+C to terminate cat command?

I have the following two test files: test1 test2 Both of them are blank. Now I issue the following commands: $ cat > test1 Enter This is a test file Enter Ctrl + D $ cat > test2 Enter ...
2
votes
1answer
5k views

Is cat the only reliable command that can read data from serial?

I have a scale that continuously send data via serial port, 2 times per second. The only reliable way on reading this data happened to be cat command. The following works: cat /dev/ttyUSB0 But the ...
0
votes
1answer
1k views

Pipe data from TCP socket connection to terminal

I have this simple line writing JSON to a TCP server echo "{\"some\":\"json-data\"}" > /dev/tcp/localhost/9091 > cat I would have thought that some connection would be created, and the data ...
1
vote
3answers
312 views

How can I concatenate two files, foo1 and foo2, but also insert some text after foo1 and before foo2 from the terminal?

I would like to do something like cat foo1 foo2 | How can I enter sometext from terminal | > foo3 where foo3 contains the contents of foo1 followed by sometext, followed by the contents of foo2. ...
0
votes
2answers
579 views

Multiple files with no header to merge with one header

I have 58 files named as xaa.csv to xcf.csv, none of them have headers. I have a separate file with the header. How can I merge the files with the header and have 59 outputs merged? For example: ...
0
votes
0answers
139 views

What is the fastest command to trim the header of a csv file?

I need to trim the header in a csv file. I have used tail -n +2 ... which works fine but it is really slow (I have lots of 100M files), and I don't understand why since no memory is needed from tail ...
2
votes
3answers
756 views

Cat in expect script adds new line to end of string

I have the following in an expect script spawn cat version expect -re 5.*.* set VERSION $expect_out(0,string) spawn rpm --addsign dist/foo-$VERSION-1.i686.rpm The cat command is getting the version ...
0
votes
1answer
1k views

timeout causes while read loop to end when `cat` is timed out

I am unable to discern why timeout in a function call will cause a loop to stop. I have a "solution", but I am really very intrigued as to how / why this is happening! It seems to be something to do ...
0
votes
1answer
149 views

Cat file dealing with header?

I'm running the following command to download a single file from git: git archive --remote=ssh://host/pathto/repo.git HEAD README.md The contents of the file are directed to terminal, before I see ...
1
vote
3answers
773 views

How do I create a file name for my email attachment?

I'm using Amazon Linux and am creating a bash script. I'm tryhing to email an attachment and am having success with (cat $TFILE1; uuencode $output_file $output_file) | mailx -s "$subject" "$to_email"...
2
votes
2answers
4k views

Difference between 'cat < file.txt' and 'echo < file.txt' [duplicate]

I have a file named file.txt which has some content say 'abcdef', when I do cat < file.txt I get the output abcdef but when I do echo < file.txt, no output is returned. Why doesn't the input ...
0
votes
3answers
1k views

Append lines to beginning of all files in a directory

I am trying to prepend two lines to the beginning of all the files in a directory. I can do it for an individual file using the following command: echo -e "% First Line\n% "$(date)"\n\n$(cat file1....
1
vote
2answers
472 views

How to cat /dev/ttyUSB0 to new file daily

I have a script that simply does this: cat /dev/ttyUSB0 > /home/pi/usb0_$(date +\%Y\%m\%d\%H\%M\%S).txt It runs great, but I want to create a new file each day instead of one big file. I ...
0
votes
1answer
709 views

Base64 decode and overwrite file

I have a file which contains base64 encoded image data: ~/dog/1.jpg I put it there via SSH, and base 64 encoded the data so it would be safe to transfer in the terminal. Assume the base64 image data ...
1
vote
2answers
1k views

Working with /dev/null with cat or cp vs touch

In a tutorial about public key infrastructure the author sets up a database to work with when setting up a Root Certificate Authority: cp /dev/null ca/root-ca/db/root-ca.db cp /dev/null ca/root-ca/db/...
0
votes
2answers
133 views

Concatenate files from line number onwards

I have two text files, file_1 and file_2. How can I concatenate file_2, from line 20 onwards, with file_1?
1
vote
2answers
4k views

Display all files from a directory with cat at the same time

I'm writing a script that would allow me to view the content of every file in an entire selected directory but I don't quite know how to do it. I was thinking about piping the output of ls into cat ...
-2
votes
2answers
886 views

cat error in shell

I am using the following code to write files iteratively in 20 folders for job scheduling. #!/bin/bash for i in {1..20} do cd conf$i cp ../nvt.mdp $PWD cp ../topol.top $PWD ...
5
votes
3answers
2k views

How to run local (non-shell) scripts on a remote host via SSH?

How can I make cat someFile | ssh someHost work when someFile is not a bash script? I want to remotely execute a perl script but I get a bunch of syntax errors from bash when I try the cat | ssh ...
-4
votes
1answer
472 views

Difference between simple cat and redirecting the to a variable

I have written the following script #!/bin/bash echo "Power Details" fall='/sys/class/power_supply/BAT1' full=cat $fall/energy_full echo 'printing here' echo $full It is showing the following error: ...
2
votes
3answers
293 views

Concatenate consecutive files

I have a list of videos in a directory that I want to concatenate. Video1.mpg Video2.mpg . . . Video35.mpg I want to concatenate this in the order of their number without having to write all of them ...
0
votes
1answer
427 views

appending to remote file over SSH leads to line-by-line expansion

I'm trying to append a certificate to a remote server's certificates file, using the folliwing command openssl s_client -connect host:port | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | ...
0
votes
8answers
1k views

How to cat all lines together in file/for all files in a directory

I have 100's of files in a directory that contain lines of text. I want to concatenate all the lines in a file into a single line. I would like to do this for all files in a single pass. cat does not ...
7
votes
1answer
903 views

What is meant by “keeping the pipe open”?

I've been following walkthroughs for various exploit exercises for linux applications. I understand the content of these well enough, however some refer to using cat to "keep the pipe open", e.g. here....
0
votes
1answer
67 views

Permanent Solution to : files, strings w/o \n mixing to command line [duplicate]

file contains no newline terminator. final line of file is mixed to the username in command prompt. file: line 1 test: user /: cat file line 1user /: Solution is suggested to be : to add a new ...
0
votes
2answers
135 views

cat file : prints prior to “user :/” prompt

file contains just 1 line: aaa when I run "cat file" it mixes to username user /dir : cat file aaauser /dir : What could be the problem ? Extra Info: perhaps this is not properly set in bashrc ? ...
0
votes
0answers
43 views

Concatenate 2 files in a loop that differ for only one word [duplicate]

I have several pairs of files that i have to concatenate. They differ of only one word (positive vs negative) like: 1.sorted.bam.bed.negative.trimmed.10.bed 1.sorted.bam.bed.positive.trimmed.10....
1
vote
2answers
194 views

Large replace in XML

Okay, so I have this xml file. I need to replace every key value with a value from another file (txt). Both files are sorted so line 20 i.e inside the xml <word key="ACTIVE" group="Service ...
6
votes
4answers
6k views

How to cat files together, adding missing newlines at end of some files

I have a bunch of .text files, most of which end with the standard nl. A couple don't have any terminator at end. The last physical byte is (generally) an alphameric character. I was using cat *....
-2
votes
1answer
466 views

Concatenate files that end with a specific set of characters

I need to concatenate files whose names have a second to last character in the file name in the list of acegik and the last character as a 1. Do I need to use grep for this problem?
2
votes
1answer
358 views

Appending content to file gives permission denied error [duplicate]

I am trying to append some config to another file like this sudo cat config/add-this.yml >> ~/docker-compose.yml via shell script. But trying this gives me a Permission denied error. How can ...
1
vote
1answer
8k views

How does cat > file << “END” work?

$ cat > file << "END" > asdf > qwerty > END $ cat file asdf qwerty $ Not sure how does the above trick work. cat > file is somewhat understandable for me, it means that the ...
0
votes
2answers
901 views

How to concatenate two files in a loop?

I have two files that I want to concatenate in one new file, but I want to do it by using a loop because I have different directories (a, b, c, g and z) with same 2 files. My loop is: for i in a b c ...
1
vote
1answer
2k views

Would cat *.txt concatenate files in alphabetical order? [duplicate]

Let's say that I have 3 files in a directory: apple.txt: apple beehive.txt: beehive zebra.txt: zebra If I concatenate this files with: cat *.txt > all_files.txt I do get: apple beehive ...
2
votes
1answer
287 views

Coloring script output using cat [duplicate]

Is coloring an output possible using cat or similar command? Let say I have some php or bash script or other. I don't need to edit the file, just to view the source. So cat filename does the job. ...
0
votes
2answers
102 views

Is there a way while using tail to get it to tell number of lines without using cat?

I'll share an example so it makes sense - [$] cat /boot/config-4.9.0-1-amd64 | tail 7856 CONFIG_FONT_SUPPORT=y 7857 # CONFIG_FONTS is not set 7858 CONFIG_FONT_8x8=y 7859 CONFIG_FONT_8x16=...
0
votes
1answer
49 views

Managing duplicated lines across files [closed]

I am generating all the common/duplicate lines between 5 files all within the same directory sort *.txt | uniq -d > output.txt I need output.txt to be merged with File1.txt (so anything that isn'...
1
vote
1answer
2k views

How does “cat” handle large files when used as part of a pipe?

Suppose I cat a file having size of say 10 GB, and I pipe that to head, would cat work if my system only has 2 GB of RAM and 1 GB of swap space? I want to know the internal details.
0
votes
2answers
69 views

RegEx match + additional line removal

So I am pretty new to what I currently refer to as "advanced" RegEx, please pardon me, it's probably really easy for you guys but I need to be pointed in the right direction because right now I am ...
2
votes
3answers
4k views

Find files and echo content on shell

Im trying to search all files within a directory by name and outputting the files' content onto the shell. Currently I'm only getting a list of files find -name '.htaccess' -type f ./dir1/.htaccess ...