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

Write output of command to specific line

I need to write the output of a command to a specific line in a document. I can not just append it like so COMMAND | cat >> file, I need it to be added between two lines without replacing one or the other. I'm sure you must be able to do this via…
user3094719
  • 297
  • 4
  • 16
0
votes
2 answers

Sed from Serial Stream

I'm using a Raspberry Pi with a Serial device connected over USB (/dev/ttyACM0). I can write the data to the console with cat /dev/ttyACM0. But when I try to replace the $ signs in the output with a newline cat /dev/ttyACM0 | sed 's/\$/\n/g' i get…
heysamhey
  • 530
  • 1
  • 6
  • 17
0
votes
1 answer

extracting first line from file command such that

I have a file with almost 5*(10^6) lines of integer numbers. So, my file is big enough. The question is all about extract specific lines, filtering them by a condition. For example, I'd like to: Extract the N first lines without read entire…
Jonathan Prieto-Cubides
  • 2,577
  • 2
  • 18
  • 17
0
votes
1 answer

using cat in a bash script is very slow

I have very big text files(~50,000) over which i have to do some text processing. Basically run multiple grep commands. When i run it manually it returns in an instant , but when i do the same in a bash script - it takes a lot of time. What am i…
nikel
  • 3,402
  • 11
  • 45
  • 71
0
votes
1 answer

use cp to copy and change name of a file reading from a filelist.file

I want my script to copy the files in addresses.list (which contains the absolute path of those files) in my folder3 adding to the name of files the variable k (name of the lower folders they came from). The script makes sense to me but it does not…
alikino
  • 23
  • 4
0
votes
1 answer

cat passwd | awk -F':' '{printf $1}' Is this command correct?

I'd like to know how cat passwd | awk -F':' '{printf $1}' works. cat /etc/passwd is a list of users with ID and folders from root to the current user (I don't know if it has something to do with cat passwd). -F is some kind of input file and {printf…
Sean Sabe
  • 79
  • 9
0
votes
2 answers

how to append the text from daughter files to a single mother file and deleting headers from daughter files

During a structural simulation, I get the following response in a file.txt: constant date 03/23/2011 {BEGIN LEGEND} Entity # Title 1 blank …
0
votes
1 answer

How to create a shell alias with parameters

I need to check a lot of configuration files and like to cat them without the lines beginning with comments. I am typing the following in the shell: egrep -v '^[[:blank:]]*#' *filename* | awk 'NF' which works: $ egrep -v '^[[:blank:]]*#'…
Romain Jouin
  • 4,448
  • 3
  • 49
  • 79
0
votes
5 answers

Delete duplicate headers in awk

I used used cat to combine several files and they all have the same headers. Is there anyway I can retain the 1st occurrence of the header and delete the succeeding headers inside the concatenated file? Thanks! Example: FirstName, LastName, Phone,…
Johann
  • 3
  • 4
0
votes
3 answers

Extracting the pattern from the line

How can I extract words which contains the pattern "arum" from the following line: Agarum anoestrum alabastrum sun antirumor alarum antiserum ambulacrum antistrumatic Anatherum antistrumous androphorum antrum 4. foodstuff foody nonfood Aplectrum…
0
votes
1 answer

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 someone can show me a way to do this much more…
Christian Bongiorno
  • 5,150
  • 3
  • 38
  • 76
0
votes
2 answers

Use pipe line to open a file after it's just created

I want to achieve something quite simple with pipeline: step 1 : cat input1 input2 > output step 2 : gedit output I can do cat input1 input2 > output | gedit output But I wonder how can I ommit typing the name of output file in this case? So the…
Arch1tect
  • 4,128
  • 10
  • 48
  • 69
0
votes
1 answer

C - infinite read from cat in Device file

I've been having some headache with infinite reads from cat (cat doesn’t close because it doesn’t receive end of function from my read function. How can I implement an end of read so that reading the file with cat will only produce 1 output per…
kprintx
  • 1
  • 2
0
votes
1 answer

Extract text files in each subfolder and join them with the subfolder name

I have compressed text files in the following folder structure: ~/A/1/1.faa.tgz #each tgz file has dozens of faa text files ~/A/2/2.faa.tgz ~/A/3/3.faa.tgz I would like to extract the faa files (text) from each tgz file and then join them using the…
Fernando
  • 93
  • 1
  • 9
0
votes
3 answers

Sum the number of lines from different files

I need to sum the number of lines from different text files like: x_red, x_green which have some information inside of them, and this is what I got: counter=0 colors=`cat manyColors.txt` addPrefix(){ echo "x_$1" } for color in colors do # …
jruivo
  • 447
  • 1
  • 8
  • 22