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

simpler way to extract and count data

I need to extract specific information from my data and the summarize it. I have 246 files that I need to do the same thing. So I did for f in *.vcf; awk -F"\t" 'NR>1 {split($10,a,":"); count10[a[7]]++} END {for (i in…
Jan Shamsani
  • 321
  • 2
  • 5
  • 14
-1
votes
1 answer

how to use script with sed command in linux?

How can I use the sed command (in Linux) to find the 1000th line in a file with 10000 lines and replace just that one line with another? Thanks in advance!
Bhushan Ahire
  • 79
  • 1
  • 6
-1
votes
2 answers

How do I concatenate 2 files follow a some pattern?

What I want to do is simply concatenate 2 files like the following example: file 1 file 2 C1 O1 C3 O3 .. O5 O7 O9 O11 O13 O15 …
git
  • 151
  • 9
-1
votes
2 answers

Append two columns adding a specific integer at each value in Unix

I have two files like this: # step distance 0 4.48595407961296e+01 2500 4.50383737781376e+01 5000 4.53506757198727e+01 7500 4.51682465277482e+01 10000 …
-1
votes
1 answer

Can gnu parallel be used with the cat command and large arrays?

I am working on processing a long list of data from a file using bash. There are over 300,000 lines in this file, so using gnu parallel could cut down processing time significantly. In addition to the main data file, I am using a second, smaller…
gwilymh
  • 415
  • 1
  • 7
  • 20
-1
votes
3 answers

Using the command line to combine non-adjacent sections of a file

Is it possible to concatenate the headers lines in a file with the output from a filter using grep? Perhaps using the cat command or something else from GNU's coreutils? In particular, I have a tab delimited file that roughly looks like the…
lmo
  • 37,904
  • 9
  • 56
  • 69
-1
votes
1 answer

Parsing log file into multiple unique log files

I have a centralized log file that I'm trying to parse out into multiple files to make it a bit more manageable. The file contains lines looking like this 2015-04-02 16:03:13 -0500 192.168.3.3: shell login for 'rancid' from 192.168.50.10 on…
Axis
  • 3
  • 2
-1
votes
2 answers

Reading an array from a file in bash - "not found" errors using cat

I have a text file with a few basic words: -banana -mango -sleep When I run my script: #!/bin/sh WORD_FILE="testwoord.txt" WORDS_ARRAY=cat $WORD_FILE The output is like: /home/username/bin/testword.txt: 1 /home/username/bin/restword.txt: banana:…
Mirwais
  • 1
  • 1
  • 6
-1
votes
1 answer

php putting an array from _construct into function

II'm using an API and was wondering why I am having trouble getting an array to cross into a function. The following works fine but how can I make it work for an array. public function __construct() { parent::__construct(); // Init parent…
martyn
  • 230
  • 5
  • 22
-1
votes
1 answer

make android source using adb shell command "cat"

I want to use shell command, 'cat'. I want to copy the "abc.jpg" file..But It didn't operate. What is the problem? Thank you. public void onClick(View v) { Runtime runtime = Runtime.getRuntime(); Process process; …
-1
votes
1 answer

Combining txt and csv files in a ton of folders into one big csv file

How would you go in Linux about combing all files of this archive: https://github.com/tpb-archive/4xxxxxx/ into one or several big csv files? Or the better question: How would you go about putting this whole archive into a WordPress blog? With…
-1
votes
1 answer

merge list of files using a loop (bash)

I am working in bash (Fedora). I have a list of text files as follows: filenameA filename1 filenameA filename2 filenameA filename3 filenameB filename4 filenameB filename5 I wish to combine (cat) all of the files listed in second column…
Trevor
  • 1
  • 2
-1
votes
2 answers

cat files in subdirectories using linux commands

I have the following directories: P922_101 P922_102 . . Each directory, for instance P922_101 has following subdirectories: 140311_AH8MHGADXX 140401_AH8CU4ADXX Each subdirectory, for instance 140311_AH8MHGADXX has the following…
chas
  • 1,565
  • 5
  • 26
  • 54
-1
votes
1 answer

How can I match the header of a .CSV file with dynamic field names

I hope this cut-down version of my previous question sounds much better than earlier. I have a .CSV file (frequency - weekly) whose header contains the year-week value in two of the columns which keeps changing every week. For an instance please see…
Dhruuv
  • 343
  • 10
  • 24
-1
votes
2 answers

How to make a .cat file from a .txt file

I'm having trouble in converting a .txt file into a .cat file. It's a dictionary (LIWC2007 italian)which separates words into categories; I have to load it on WordStat 6.1. WordStat won't see any non-.cat files when I try to load the…
pepegna90
  • 1
  • 2