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
4 answers

adding an html comment at the top in bash

Hello i have to write a short program to take in an input and add it to the top of file and add a timestamp into the bottom of the file also in an html comment. just a little confused how to do this echo "What would you like to add to the top of the…
user2569803
  • 637
  • 6
  • 11
  • 19
0
votes
3 answers

how to grep external txt file in bash script?

I would like to run a script that can be access in other terminals other then my own. like bash <(curl -s http://domain.com/scripts/hello.sh) but I need this script to grep a txt file that is also located on that server for example…
Chris Ivie
  • 21
  • 4
0
votes
2 answers

view content of files from grep -L

I use grep -L to get a list of files that do not contain a certain string. How can I see the content of those files? Just like: grep -L "pattern" | cat
aldorado
  • 4,394
  • 10
  • 35
  • 46
0
votes
1 answer

Copy files from remote server over ssh inside a loop

I'm trying to download some files over ssh. Files are in folders (folder1 folder2 folder3), so I decided to loop. The following doesn't work: ssh user@remotehost 'for i in 1 2 3; for filename in /folder$i/*.log; do cat /$filename > /localdrive;…
0
votes
1 answer

How can I split subdirs into smaller chunks for /bin/cat

I have the following situation. A directory with really a lot of subdirectories, and each of those subdirectories contains a file of interest that I want to concatenate. e.g., my_dir/ subdir1/ subsubdir/ …
user2489252
0
votes
2 answers

LINUX: Using cat to remove columns in CSV - some have commas in the data

I need to remove some columns from a CSV. Easy. The problem is I have two columns with full text that actually has commas in them as a part of the data. My cols are enclosed with quotes and the cat is counting the commas in the text as columns. How…
karnival8
  • 693
  • 1
  • 5
  • 7
0
votes
0 answers

Cat isn't working on certain files

I'm trying to read some files on an Android device using cat. Specifically, I want to…
Kmanc
  • 349
  • 1
  • 5
  • 20
0
votes
4 answers

change filenames in lists of files: slow script

I want to change the name of the files stored in a series of filelists. This is the code I am using: suffix=[event] for i in {0..9} a b; do for file in $(cat gsc"${i}".list); do echo $file$suffix done done The output is fine, but…
Py-ser
  • 1,860
  • 9
  • 32
  • 58
0
votes
1 answer

Add strings and tags at the beginning and end of each line

I have recently started using Ubuntu and catching up on lots of stuff - can somebody please assist a little bit. I have a file (pictures.txt) with 300 lines like this: Kitchen Cookie Soup Garden Flower Make-up I would like to add a tag,…
0
votes
1 answer

Appending files on Mac is adding strange unprintable characters

when I run a command like: cat file1.js file2.js file3.js > all.js On mac osx the all.js has strange characters prepended at the boundaries of the files. The strange characters are the following values in hex editor: EF BB BF Anyone know what OS…
JayPrime2012
  • 2,672
  • 4
  • 28
  • 44
0
votes
1 answer

Using cat in a bash script : escaping troubles

I'm very bad at regex and escaping characters. I want to use the 'cat' command in a bash script like this : echo `cat working-dir/*OUTPUT` ; That should print on screen, every files in the working-dir that end with "OUTPUT" but this is not…
Gui O
  • 363
  • 4
  • 8
  • 22
0
votes
2 answers

script for checking directories and file contains a word

I have the following file "nbr_chk.txt" ,this file contains numbers that can be in any directory (from 1 to 10). the sub directory where they are is the 5th and 6th number nbr_chk.txt 612345678 623456789 634567890 I want to make a script using…
BigBen59
  • 123
  • 3
0
votes
2 answers

Remove lines from head and tail of multiple text files and merge

I have multiple text files with different data, but same header & bottom text. I have to remove the header and tail text and merge them into one output file. Any one liner with decent speed would be good. All of the file names Start with the name…
Muz
  • 73
  • 1
  • 8
0
votes
4 answers

Joining files with cat

i'm doing a script to download one file in multiple parts, i'm in the part of joining that files. I can join the parts outside of the script with cat name.part{0..4} > name.ext But, if i use this in the script cat $filename.part{0..$N} >…
fpilee
  • 1,918
  • 2
  • 22
  • 38
0
votes
2 answers

Grep and Regex an HTML File

I have an HTML file with thousands of lines, but something is repeated. CODE=12345-ABCDE-12345-ABCDE
... Now, The line starts with "CODE=" every time, and the length of the code is the same…
Goodies
  • 4,439
  • 3
  • 31
  • 57