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
0
votes
2answers
247 views

Grep file contents EXCEPT match case WITH context

I have a file test.txt, with contents like theese: line random text 1 line random text 2 line random text 3 line particular exception line except detail 1 line except detail 2 line except detail 3 .....
0
votes
1answer
89 views

Create new concatenated files of same name in multiple directories

I have many files of the same name distributed in many sub-directories with different names (though all at the same level). I'd like to concatenate all the files of the same into a new file with that ...
2
votes
1answer
131 views

Here-document with cat

I am new to Linux, shell scripting, and I'm trying to learn the fundamentals. I am currently on the redirection chapter, where here-documents are being explained. I could not really understand how the ...
0
votes
1answer
121 views

Garbage char “^@” shows using vim but using cat it shows proper data

I am trying to copy the x.file data into virtual volume of size 32 KB and trying to read again 32 KB from the same volume to y.file. It shows expected output when using cat y.file but whenever I am ...
1
vote
3answers
74 views

Insert lines from an input file every n lines in awk

With input files A and B as such: File A 1 1 1 2 2 2 3 3 3 File B 10 10 10 20 20 20 30 30 30 40 40 40 50 50 50 60 60 60 70 70 70 I would like to insert one line of file A every 3 lines of file B,...
-1
votes
2answers
94 views

How to create a file with some specific content using shell script? [duplicate]

In the middle of a shell script, I need to create a file with some specific content. How do I do it? Can it be done using cat?
0
votes
2answers
76 views

Combine multiple files into single file, append portion of each file name

I have a few hundred files that each contain a single numeric entry (ex: 5243564). Each file name has an identifier (FT, FM, FA, etc) and a date (ex: FT.20180315.txt). I would like to combine ...
0
votes
2answers
39 views

How do I create a new txt file from another file which is a list?

I'm trying to create a second config file from a file with a list of domains. File1 (file1.txt) contents example.com example.org example.net . . . I want to automatically create this second ...
0
votes
1answer
139 views

How can one remove a range of lines for every group of n lines? [duplicate]

I want to start with a file that looks like this: 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 Return only the last three of every group of five like so: 3 4 5 3 4 5 3 4 5 I've managed to get the first 2 using ...
-1
votes
3answers
358 views

Why cat command doesn't use its command environment? [duplicate]

AFAIK, cat is an external command and it forks off a new process when executed, just like sh -c or executing a script. With that said I expect cat to use its command environment as it is used by ...
1
vote
1answer
39 views

pipeline processing using cat

original: ./A_process.py _ < input.dict > output.dict.tmp ./B_process.py _ < output.dict.tmp > output.dict rm output.dict.tmp I am trying to make it into a pipeline, so cat input.dict | ...
0
votes
0answers
56 views

cat commad outputs vast amount of characters (some are jibberish-like): What do these mean? [duplicate]

What the heck does all that mean? I dont recognize most symbols? Does it have any legitimate uses to just spray out an image file in gibberish? Can patterns be pulled from that? fHp$yE.bf!Xa>:3&...
19
votes
6answers
5k views

cat a very large number of files together in correct order

I have about 15,000 files that are named file_1.pdb, file_2.pdb, etc. I can cat about a few thousand of these in order by doing: cat file_{1..2000}.pdb >> file_all.pdb However, if I do this ...
1
vote
1answer
105 views

how to change text string with shell script

/home/temp.txt http://url_new_address.com /home/list.txt URL http://url_address.com:URL1 URL http://url_address.com:URL2 URL http://url_address.com:URL3 How can I replace the line in temp.txt with ...
1
vote
2answers
314 views

How to combine multiple files with similar names in different folders by using unix command?

I know this question has been asked and answered before, I have tried the code but I do not get a correct output. I have 2 folders: vanila1 and vanila2, each has 400 files with similar names ls ...
0
votes
1answer
36 views

combining two files to a single file

I have a folder with 700 files (350 individuals, for each I have 2 files R1 and R2), HI.2622.001.Index_16.ED16_KS1W9-3_342_R1.fastq.gz_matches_default.fit_ID_90.fit_ID90_e HI.2622.001.Index_16....
1
vote
1answer
338 views

Piping cat into wall (e.g. cat | wall)

Why does echo foo | wall work but cat | wall not work? In the latter case, I enter a couple lines into cat, and in theory they should pipe to wall; however, nothing happens.
3
votes
3answers
2k views

Redirect content under a new line (without further syntax or arguments)

I tried these ways to append content to a file: printf "\nsource ~/script.sh" >> /etc/bash.bashrc echo -e "\nsource ~/script.sh" >> /etc/bash.bashrc cat >> "/etc/bash.bashrc" <&...
5
votes
2answers
7k views

How to cat and sed together? [duplicate]

I have this cat then sed operation: cat ${location_x}/file_1 > ${location_y}/file2 sed -i "s/0/1/g" /${location_y}/file2 Can this be done in a single line? I might miss such a way here, but that ...
3
votes
2answers
314 views

cat-redirect a file, but with variable expansions

I have the file ~/nginx_app containing this conf template: server { root /var/www/html/${domain}/; server_name ${domain} www.${domain}; } I also have this script: #!/bin/bash domain="$1" &...
1
vote
2answers
734 views

why does ssh -t option adds cr & lf in redirected output

I connect from my windowsbox with putty to a linux box. After that I do the following: on Server A: serverA: file /etc/motd /etc/motd: : ASCII English text on Server B: serverB: ssh -t user@...
0
votes
0answers
48 views

keep reading files in an updated dir

I have directory, that gets new .gz files during the day. I'd like to have a scripts that I start in the morning, and which keeps reading the data (and possibly processing it) as the new files are ...
0
votes
5answers
139 views

How to find contents of a file?

How do I display content of files with name containing letter 'a' in it? I tried cat|ls|grep 'a'
1
vote
3answers
6k views

write multiple lines to a file in one line command [closed]

I have a file that i want to create using command line, using the cat tool (or something similar). The text in question is multi line and is in a certain format (yaml) - which i want to maintain. Is ...
0
votes
3answers
86 views

How to get line strings with special word start and end? [duplicate]

Here is the file strings.xml which includeing 3 sentences: 1.string name="schedulelist_nofiles">Não existe agenda de registro! Por favor, here is missing line tecla “Add” (Adicionar) para adicionar ...
1
vote
5answers
661 views

How to append multiple lines to a file, if these lines doesn't exist in that file?

How to append multiple lines to a file, if these lines doesn't exist in that file? For example, to add multiple global aliases to /etc/bash.bashrc I use an heredocument: cat <<-"BASHRC" >&...
-2
votes
2answers
3k views

What is the difference between “grep -c ^b example” and “grep ^b example| cat –n”?

I'm trying to learn command line better and wondering what the difference between these two commands would be. grep -c ^b example and grep ^b example| cat –n
1
vote
1answer
125 views

How to display cat (not man) pages?

I recently discovered that, in addition to man 👨 pages, some UNIX documentation is also available as cat 🐈 pages. (Cf. this question: What is the deal with mandb and stray cats?) From man catman: ...
4
votes
1answer
251 views

Why does bash replaces text from command substitution with text thereafter

I was trying to parse some nginx config λ tree sites-enabled/ sites-available/ sites-enabled/ ├── bank.cwrcoding.com.conf ├── calendar.cwrcoding.com.conf ├── cloud.cwrcoding.com.conf ├── cwrcoding....
0
votes
2answers
44 views

Source multiple sql files with blank in name

I'm actually blocking on a stupid thing ... yet i can't get it throught. We've got a git repository on which we have our php files and our sql patch. Every time i update my repo, i have to check if ...
0
votes
1answer
70 views

How to merge two files containing lists to one file with two columns?

I have the file mail.txt which contains the list of some emails and the file names.txt that includes the names of those people accordingly. Now I want to combine these files to one files with the ...
0
votes
1answer
62 views

Cannot write text in a file when using here-document [duplicate]

This command doesn't seem to work in my script, how can I decide in which file I want this text, if I just create a file with the following command touch $name I want the text to be in the file $...
0
votes
1answer
46 views

Inconsistent behavior when modifying file in-place with cat, sort, tee, and pipes [duplicate]

Situation: When using the following command: cat foo | sort | tee foo where foo is a text file of multiple lines, the outcome is not consistent. The two outcomes I've observed are: The file is ...
0
votes
1answer
37 views

How to code automatic uncompression of files in sh?

I'm coding a shell script, that processes log-files. Sometimes the files may be compressed -- and have the appropriate suffix in the file name. I'd like to add the decompression to the file-...
0
votes
2answers
250 views

Append to a file with sudo [duplicate]

I have a file named foo whose permissions are -rwxr-x--- root and I'm neither the user (root) nor in the group. I have another file named bar, which I want to append to foo. I've tried sudo cat bar &...
2
votes
3answers
5k views

scp remote file and append to local file

I have multiple files to be pulled from remote server. For further processing of the files in the local server, I need to merge (concatenate) them into single file, which can't be done in the remote ...
0
votes
1answer
396 views

serial device output looks fine in gnu screen but garbled using cat

I have a serial device (Omega RDXL4SD thermocouple reader, comms details p 22 here) connected to a USB port on my Raspberry Pi running Raspbian via an FTDI cable. It appears at /dev/ttyUSB0 and the ...
0
votes
2answers
32 views

linux + file printed with the linux prompt

when we print the file- /etc/hosts.txt we get after the last line the - [root@master02 data]# , why? we try dos2linux , and by vi we not see any charterer after the last line - worker03.yu.com 14.23....
1
vote
1answer
42 views

cat heredocument copied everything besides function call

I executed the following code in my Bash console in an Ubuntu 16.04 environment: cat <<-'DWA' > /opt/dwa.sh DWA() { test='test' read domain find /var/www/html/ -...
1
vote
1answer
50 views

Different cat Output for Hard Linked File over SSH? [closed]

I have a single initial file created using a C program on OpenSUSE Leap VirtualBox VM being accessed via ssh from OS X. The file is created with mkstemp() that a hard link is created for using link(). ...
0
votes
2answers
695 views

How do I send a set of file paths to cat and display their contents? [duplicate]

to be more specific ,I want to display contents of files from output of find command,I tried the following commands but they don't get my work done cat < find . -name "*.txt" find . -name "*.txt" |...
3
votes
1answer
949 views

How does this command work? mkfifo /tmp/f; cat /tmp/f | /bin/sh -i 2>&1 | nc -l 1234 > /tmp/f

Today I was reading the nc man page and stumbled on this command. I know that: mkfifo /tmp/f is creating a named pipe at /tmp/f. cat /tmp/f is printing whatever is written to that named pipe and the ...
1
vote
1answer
1k views

How to display trailing whitespaces in the text file?

I'd like to be able to print and see the trailing whitespaces in the text file (just display, not remove). I've tried with cat -v which suppose to display non-printing characters, but it doesn't ...
1
vote
1answer
347 views

How cat suspends while reading a port?

When we cat a regulat text file's content, everything is printed out and the command terminates. However, when we cat /dev/ttyS0, the command hangs and waits new data to come. What is the reason of ...
0
votes
2answers
814 views

Cat a file with grep, showing current “cat” line

I search through a HUGE file with cat and grep. I need to know on which line is cat all the time. If i want to search ball: cat file.txt | grep ball FILE: football tennis hockey basketball ... ...
-2
votes
3answers
355 views

Bash Cat file to terminal centre

I have a text file with aome ascii art in it. I am trying to get it to print to the terminal on terminal start. I know to do this i add cat myfi in my .bashrc. i am stuck trying to get the output of ...
5
votes
5answers
3k views

How to cat all the log files within a range of dates

I have log files which are named in the following manner: localhost_log_file.2017-09-01.txt localhost_log_file.2017-09-02.txt .... localhost_log_file.2017-10-30.txt In other words, each log file ...
8
votes
6answers
16k views

How to add headers to columns [duplicate]

I have data: 7456 7456 0 0 0 2 7463 7463 0 0 1 2 I want to add column headers so the output is: FID IID PAT MAT SEX PHENOTYPE 7456 7456 0 0 0 2 7463 7463 0 0 1 2 I have tried echo -e "FID\tIID\...
0
votes
2answers
566 views

How to detect main class name from a java file having multiple classes using shell script?

I make a script javaFilesConcatenator using cat and sed, that concatenate multiple .java files: #!/bin/bash ############################################################################################...
1
vote
1answer
3k views

copy files and append in another directory?

I have five directories Dir1, Dir2, Dir3, Dir4, Dir5. In each directory, I have five text files (which are named as file1.txt, file2.tx,.file5.txt) that contain data. What I want is to copy file1.txt ...