Questions tagged [cat]

The cat command is a standard Unix program used to concatenate and display files. The name is from catenate, a synonym of concatenate.

cat - concatenate files and print on the standard output.

The cat command is used for:

  1. Display text file on screen
  2. Read text file
  3. Create a new text file
  4. File concatenation
  5. Modifying file

Example

$ cat -n file #shows the content of a file, including the line-numbers(-n flag)

Concatenating two files into third file:

cat file1 file2 > output_file 

The purpose of cat is to concatenate (or catenate) files. If it is only one file, concatenating it with nothing at all is a waste of time, and costs you a process." This is also referred to as "cat abuse". Nevertheless the following usage is common:

cat filename | command arg1 arg2 argn
cat -- "$file" | grep -- "$pattern"
cat -- "$file" | less

can instead be written as:

grep -- "$pattern" "$file"
less "$file"

A common interactive use of cat for a single file is to output the content of a file to standard output. If the output is piped or redirected, cat is unnecessary.

Without two named files, the use of cat has no significant benefits.

Useful links

1519 questions
-1
votes
2 answers

Replace a semicolon followed by a backslash by just a semicolon and dont apply it to other baskslashs alone

I have a file that contains data that looks like this…
akmot
  • 63
  • 8
-1
votes
2 answers

How to see several lines under one grep line

I want to see the logs where log level is ERROR and I want to see the stackTrace but when I input like below cat app.log | grep ERROR I can't see the stackTrace Is there a way to see several lines under the greped line?
user17803116
-1
votes
1 answer

Run cat on remote computer and send output a variable using expect

I have a bash+expect script which has to connect via ssh to the remote comp (and i can't use ssh keys, need password identification in here), read the file there, find specific line with the "hostname" (like "hostname aaaa1111") and store this…
lugger1
  • 1,843
  • 3
  • 22
  • 31
-1
votes
3 answers

Add text column to result of cat & awk

I have a series of .txt files with tables of numbers, and I extract form each file the number I want. Example: for f in $(find . -name "E_total_conv.txt"); do cat $f | tail -1 | awk '{print $2}' ; done The…
Argento
  • 3
  • 3
-1
votes
1 answer

Incomplete paste in a file (using cat) when copy selection from terminal

I am trying to copy output from the Mobaxterm terminal in a file in Ubuntu 20.4 running on Win 10 - WSL 2. Steps I perform: I select the lines I want to copy. cat > file Paste (with Middle-Click, Shift-Ins, Right click menu & Paste) Ctrl-D to…
-1
votes
1 answer

how to combine more than two file into one new file with specific name using bash

I have many file list file name: p004c01.txt p004c05.txt p006c01.txt p006c02.txt p007c01.txt p007c03.txt p007c04.txt ... $cat p004c01.txt #header 122.5 -0.256 547 123.6 NaN 325 $cat p004c05.txt #header 122.1 2.054 247 122.2 -1.112 …
-1
votes
2 answers

Sed over a long list using cat

I am trying to change some lines of a code using sed by reading another list of 7000+ lines using cat. I tried to do : for i in `cat namefile`; do sed 's/OG0000047/$i/g' paml.ctr > paml_$i.ctr; done My code (paml.ctr): seqfile = OG0000047.phy …
user3188922
  • 329
  • 1
  • 3
  • 19
-1
votes
1 answer

bash order of commands?

after wondering how if can pipe ls into cat to output a bunch of files I realized a better way to do that is to cat $ $(ls *.py), but also realized that $(ls *.py) cat $ does not work: $(ls *.py) cat $ …
-1
votes
2 answers

How can I use the concatenate command to automate the merging of several files?

I need to merge two sets of files together. I don't mind what language is used as long as it works. For example: I have a folder with both sets of…
ertictus
  • 1
  • 1
-1
votes
2 answers

cat: pid.txt: No such file or directory

I have a problem with cat. I want to write script doing the same thing as ps -e. In pid.txt i have PID of running processes. ls /proc/ | grep -o "[0-9]" | sort -h > pid.txt Then i want use $line like a part of path to cmdline for evry PID. cat…
beginner
  • 3
  • 2
-1
votes
3 answers

Substract number from wc cmd in one line

Let's suppose test.csv contains 10 lines. I'd like to put 9 into output.txt in one command line. I tried: cat test.csv | $(wc -l) - 1 > output.txt output.txt should contain 9.
user2856064
  • 541
  • 1
  • 8
  • 25
-1
votes
1 answer

Linux print file and use it in for example a curl request

This might be a complete noob question, but I would like to know a simple oneliner to solve my problem. Imagine following: I have 5 files, could be .txt, .sql .anything. root@DESKTOP:/$ ls test.sql test1.sql test2.sql test3.sql Imagine I would…
sdev95
  • 132
  • 1
  • 11
-1
votes
1 answer

How to separate columns in linux using awk or cat

I have a file with 900.000 columns, the structure is: 1613 1200000012000500000011111....... 112345 1200000012000500000011111....... 1287659 1200000012000500000011111....... 1234 1200000012000500000011111....... 712826 …
Johanna Ramirez
  • 161
  • 1
  • 9
-1
votes
1 answer

I need to show product in a. Drop down

I have a dropdown form here at https://ariyoconcept.com.ng/quick-widget to sell all my woocommerce products. I expect that after choosing DataBubundles from the dropdown list, the subcategories of DataBundles should be shown which happens. I now…
-1
votes
1 answer

Linux Internal Process for Cat and Grep

I'm newbie to linux back round process, for example i have the below linux command, Maybe the question will duplicate here but i couldn't find answer so posting it. cat test.txt | grep hello how many back round process(s) will run? It would be…
parrotjack
  • 432
  • 1
  • 6
  • 18