Sunday, 7 October 2012

cat -- for creating and displaying short files | Unix Commands

cat

used to create, view and concatenate files.
To create a file named  file1
   % cat >file1
     line 1 
     line 2
<control-D> 
   %

<control-D>  tells the computer that what is typed is the content of the  file file1

To view a file we use cat in a different way:
   % cat file1
    line 1 
    line 2
%
To add text to an existing file 
   %  cat >file1
     line 3 
     line 4
<control-D> %
If we want to join 2 files named file1 and file 2 and create a new file named as file3
   % cat file1 file2 >file3
We could check the number of lines in the new file like this:
   % wc -l file3

Enhanced by Zemanta

No comments:

Post a Comment