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
15
votes
7answers
9k views

Change tab size of “cat” command

When I am in vim I can change the tab size with the following command: :set ts=4 Is it possible to set tab size for cat command output too?
52
votes
5answers
156k views

With the Linux “cat” command, how do I show only certain lines by number

If I use cat -n text.txt to automatically number the lines, how do I then use the command to show only certain numbered lines.
-1
votes
2answers
61 views

Display contents of the file searched by grep or find command [closed]

I have lots of directories in a certain directory and I am trying to find a specific file present in there. I used grep command recursively and was able to locate the file being present in there, but ...
0
votes
0answers
17 views

How do I monitor a Socat mounted COM Port device for a specific Char Delimiter?

I have a code like the following: cat -v -e /dev/tty03 | grep --line-buffered '^F' | while read do echo "Line Found" done How can I setup a timeout for the above While Loop. I want the "while" ...
0
votes
1answer
29 views

Can't seem to concatenate multiple files in different directories

I'm trying to concatenate multiple files together that are in different directories using the following command: ~$ find . -name ‘*.text’ -exec cat {} >> combined.text \; However it doesn't ...
1
vote
1answer
46 views

How to cat named pipe without waiting

If there is nothing in a named pipe and I do: cat my_named_pipe it will wait until data arrives. Is there a flag I can use to exit immediately if there is no data to be read? Or perhaps a command ...
0
votes
1answer
18 views

replace/remove text (sed) by a file

I want to replace/remove text all files by a file. $ echo "_uU_%UHY%^GSSD$%GWRW$T#wf4werwefF$fW#$wfdd%6blahblahblah" > pattern.txt $ sudo grep -rl "_uU" . | xargs sed -ie s/$(cat pattern.txt)//g ...
2
votes
1answer
47 views

`cat -v` for non-printing non-ascii UTF characters

cat has a -v option which converts non-printing characters to their caret notation (which is useful if we don't want the terminal to interpret the control characters literally in cat output). But ...
2
votes
1answer
59 views

Pass variable to cat [duplicate]

I have only one variable in bash script ${PHP_V} and trying to pass in nginx config file like: cat <<'EOF' > /etc/nginx/sites-available/default server { listen 80 default_server; ...
1
vote
2answers
2k views

How to merge multiple files based on a timestamp

I have 2 files File 1: 01:12:00,001 Some text 01:14:00,003 Some text 02:12:01,394 Some text File 2: 01:12:00,001 Some text 01:12:01,029 Some text 01:13:21,123 Some text I need output as ...
8
votes
2answers
14k views

Why (and how) did using cat on binary files mess up the terminal?

If I understand the cat manual correctly: 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 ...
0
votes
1answer
55 views

Display line number in head and tail command like `cat -n`

cat without -n user@linux:~$ cat /etc/sysctl.conf | head -4 # # /etc/sysctl.conf - Configuration file for setting system variables # See /etc/sysctl.d/ for additional system variables. # See sysctl....
0
votes
1answer
25 views

I am not able to update a variable through sed command

I have assigned two variables but not able to update x=$(cat /scratch/env.properties | grep ConfigPath) y=$(ConfigPath=/scratch/a/b) then sed to replace ConfigPath in env.properties sed 's/$x/$y/' ...
5
votes
2answers
76 views

What determines whether backspaces show up in a file created with cat?

I just noticed that I've seen different behavior across different systems when creating a quick test file (e.g. with sample input) via cat and redirection. Here are the steps to see what I'm talking ...
1
vote
2answers
137 views

find n most frequent words in txt file using the terminal but with the cat, “grep .” and tr -d “/r” commands

I would like to find n most common words in a text file but with the following conditions: cat to get the file. grep . to get the words. tr -d '/r' to get rid of new lines. I've managed to get ...
0
votes
3answers
76 views

create single string argument using heredoc or other technique

I am trying to execute a script on remote servers, passing the script as the last argument ntrs exec-all-ubuntu --exec `cat << 'EOF' echo "$(pwd)" echo "$foobar" EOF` The problem is that ...
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
2answers
44 views

How to delete string other than pattern?

I have a m3u file as below. I want to delete all strings except the pattern and next first line. or save the pattern and the next first line as another file. Patterns group-title="TR ULUSAL" , group-...
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 ...
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
1answer
55 views

echo strings but extra question mark was added to the output

Strange "?" got added to the filename output. SCRIPTS="/path_to_script/" SUMMER=`cat /path_to_file/summer.txt` for i in ${SUMMER}; do cat <<- EOF > $SCRIPTS/20190430_$(echo ${i})_step4.r #...
1
vote
1answer
72 views

`cat` behaves strangely on a mounted virtio directory

When I'm in a mounted directory (9p) on my gentoo-guest and do the following: TMPDIR='./foo' # The directory './foo' exists and the name 'TMPDIR' is important cat <<EOF hello world EOF I get ...
2
votes
1answer
29 views

How I can read content of the ssh key file using a path read from a file?

I need to read content of the ssh key using the given path resides in a file like following: my ssh private key is: ~/.ssh/firstname.lastname When I call cat ~/.ssh/firstname.lastname in terminal on ...
11
votes
4answers
30k views

How to use “cat” command on “find” command's output?

I want to redirect the output of the find command to cat command so I can print the data of the given file. So for example if the output of find is /aFile/readme then the cat should be interpreted ...
0
votes
2answers
38 views

How to extract lines knowing start and end lines

I have a file with 1 million lines. I want to extract lines from line 10001 to 500000 How to do this?
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
2answers
12k 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 ...
2
votes
2answers
1k 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 ...
5
votes
3answers
523 views

How to display lines in a file like ls displays files in a directory? [duplicate]

I have a long file with short lines (one word) f that I would like to inspect. It would fit on the screen if it wasn't for the newlines. If the data was already arranged in columns I could just do ...
3
votes
3answers
91k 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 ...
1
vote
4answers
717 views

Why use cat to view a file? [closed]

It seems that the purpose of cat is to concatenate several files. However, many people still use cat instead of less (or a similar program like more) to display a file. See, for example, the GNU m4 ...
20
votes
2answers
10k views

Is it better to use cat, dd, pv or another procedure to copy a CD/DVD?

Background I'm copying some data CDs/DVDs to ISO files to use them later without the need of them in the drive. I'm looking on the Net for procedures and I found a lot: Use of cat to copy a medium: ...
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 ...
2
votes
2answers
172 views

Sending a list (text file) of files and pathnames to xargs

I have a file that contains the paths of various files. files.txt : /path/to/file1.txt /path/to/file2.txt ... /path/to/fileN.txt I want to use it in a script to process the files. cat files.txt | ...
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 ...
0
votes
1answer
51 views

Why do cat and more wrap lines differently?

It seems that more adds line breaks, whereas cat does not. As a result cat results will change to fit the terminal window if I resize the window, whereas more results stay put with the line breaks ...
3
votes
1answer
8k views

cat: write error: Invalid argument

Writing to a custom character device using cat 123 > /dev/chardev gives cat: write error: Invalid argument I have changed the permissions to 666 and even tried it with sudo. Still the same ...
0
votes
1answer
53 views

“nohup cat” — write the complete content to the log file rather to concatenate file

I used the below command nohup cat fastp-filtered/OZBenth*_R1.fastp.fq.gz > fastp-filtered-merged4racon/merge_R1.fq.gz > merge_R1.out.log 2>&1 & but unfortunately, the output went ...
7
votes
2answers
2k views

cat shows nothing

My team is working on a CI environment. A ko file, named x.ko, is always generated from the CI environment at a regular time everyday and its type is ELF 64-bit LSB relocatable. Today, I found that ...
1
vote
0answers
289 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 /etc/...
2
votes
4answers
293 views

How to copy the rest of lines of a file to another file [duplicate]

I have the string xyz which is a line in file1.txt, I want to copy all the lines after xyz in file1.txt to a new file file2.txt. How can I achieve this? I know about cat command. But how to specify ...
0
votes
2answers
98 views

Is there a quickest way to count lines in file which is of 4TB in linux?

Actually I have 4 TB of Txt file as Exported from Teradata records and I want to know How many records are there in that file.
1
vote
0answers
38 views

Getting awk value and outputting to a file [duplicate]

I need to get a value from a log file which I am getting using awk at the moment. I can get the number printing on the console but when I try to put that value into a new file nothing happens. Here is ...
3
votes
3answers
563 views

insert EOF statement before the last line of file

I want to insert this cat <<EOF >> /etc/security/limits.conf * soft nproc 65535 * hard nproc 65535 * soft nofile 65535 * hard ...
2
votes
4answers
87 views

Combine large amounts of files inside a directory

I have a large amount of files within a single directory, currently 10,804 files. the amount of files can float between 5 and 100,000. I am looking for a way to combine every 250 separate files into ...
0
votes
1answer
92 views

cat shows file contents, gedit and vim show blank file

I was planning on building a current logging device with an Arduino, and tried starting off with the basic SD-card write example from the Arduino IDE sketchbook. The Serial console showed no errors, ...
25
votes
7answers
44k 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
votes
1answer
89 views

Can't see the contents of a data file in terminal

I have downloaded a number of input files from the NASDAQ website (for example ftp://emi.nasdaq.com/ITCH/01302018.NASDAQ_ITCH50.gz) After decompressing (I double click on a Mac) I can't see the file ...
0
votes
0answers
22 views

Different behaviours of sudo [duplicate]

I created a file with sudo like this: sudo touch abc.txt Which understandably set the owner to root. Now when I try to edit the file via vi using sudo, it works: sudo vi abc.txt #works But when I ...
58
votes
4answers
19k 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 ...