To print contents of the file.
cut-f 1 index
extract column from a file. In this case we specify to extract first column from index file.
prints to standard output.
But can be redirected to some other file as shown below;
cut -f 2 index > works
doesn't alter original file, regards column as seprated by spaces.
cut -d , -f 1 index
use -d option to change delimiter to column as in above case ',' (comma).
-d ' ' = single space delimiter
cut -d ' ' -f 1-3 index
extracts three column at a time delimited by space.
paste poets works
merge contents of two files on screen.
Maximum number of files that you can merge with single paste command is 12 or more depending on operating system.
contents appear on screen in orders of file specified in command & entry seprated by tab.
paste -d / chapter poets works
tells the paste command to use '/' as column seprator
paste -s chapter poets
output does not appear in column but horizontally from wach file
paste chapter poets works > file1
redirect the output of paste command to some file1 instead of standard output.
(translate) does changes to several characters in large file.
tr "[:lower"] "[:upper"]
this command changes all characters in file contents from lowercase to uppercase and displays output on standard output.
tr "[:lower"] "[:upper"] <> file3
redirects output to file3 instead of standard output
tr "chapter" "page"
searches in file1 for occurrence of word "chapter" and replaces it with word "page"
but since "chapter" has more characters than "page" last three characters(ter) from 'chapter' still remain in output.
tr -d ' '
deletes space characters from file.
tr -s l <> contents.tr
replaces repeated instances of l with single instance and writes the output to file contents.tr
find repeated lines & filter them using this command
only considers repeated lines if they are adjacent to each other
uniq -c writers
tells how much times lines appear consecutively.
uniq -u writers
tells not to print repeated lines at all to output.
so only one line of that type in whole file.
uniq -d writers
prints only repeated lines from file writers
uniq writers writers.uniq
saves output of uniq command on file writers to file writers.uniq
reports number of lines, words or characters in file
wc -l file
reports number of lines
wc -w file1
reports number of words
wc -c file1
reports number of characters.
In ASCII file each character represents bytes so in ASCII files no of characters = no of bytes
gives no of lines words and characters in file also
wc file1 file2
can use wc on more than one files
prints no of lines, words and characters in all the files of present working directory.
sorts line in file in certain order
blank lines appear first followed by
lines that start with special characters.
when first word in multiple lines are same then second word is compared and so on.
lines that begin with lower case appear after lines with upper case
sort -f filename
sort -f -r filename
sort in reverse alphabetical order with -r option
sort +1 filename
sorts alphabetically starting from second word in every line.
first word = +0
second word = +1
third word = +2 so on
grep a * sort
returns the output from grep command in sorted order
ls -l sort +4
sorts the output from ls command based on 5 column.