Code Scrappers


Simple Filters


pr

~ It adds suitable headers, footers and formatted text.

    saarthak@DESKTOP-N01EJET:~$ pr doc.lst

    2019-07-23 20:14        doc.lst         Page 1

    01|accounts|6213
    02|progs|5423
    03|marketing|6521
    04|personnel|2365
    05|production|9876
    06|sales|1006
            



head

~ It displays the first 10 lines of the file if used without an option . The number of lines user want to display can be done by using -n option.

  saarthak@DESKTOP-N01EJET:~$ head -n 3 doc.lst
  01|accounts|6213
  02|progs|5423
  03|marketing|6521
          



tail

~ It displays the last 10 lines of the file if used without an option . The number of lines user want to display can be done by using -n option.

  saarthak@DESKTOP-N01EJET:~$ tail -n 3 doc.lst
  04|personnel|2365
  05|production|9876
  06|sales|1006
            



tail -c

~ If u want to specify the data in bytes than we use -c option.Tail -c will print the last specified bytes of the data.

  saarthak@DESKTOP-N01EJET:~$ tail -c 35 doc.lst
  05|production|9876
  06|sales|1006
            



tee

~ It will select the first five lines of doc.lst and saves it to shortlist.

saarthak@DESKTOP-N01EJET:~$ head -n 5 doc.lst|tee shortlist
01|accounts|6213
02|progs|5423
03|marketing|6521
04|personnel|2365
05|production|9876
            



cut -c

~ It will cut the lines vertically. We need to specify number of vertical columns using -c option.

  saarthak@DESKTOP-N01EJET:~$ cut -c 1-6 shortlist
  01|acc
  02|pro
  03|mar
  04|per
  05|pro
            



paste

~ It is used to paste data from 2 different files side by side.

  saarthak@DESKTOP-N01EJET:~$ paste doc.lst shortlist
  01|accounts|6213        01|accounts|6213
  02|progs|5423           02|progs|5423
  03|marketing|6521       03|marketing|6521
  04|personnel|2365       04|personnel|2365
  05|production|9876      05|production|9876
  06|sales|1006
            



paste -d

~ We can specify one or more delimiters with -d. Where each field will be separated by the delimiter.

  saarthak@DESKTOP-N01EJET:~$ paste -d "|" doc.lst shortlist
  01|accounts|6213|01|accounts|6213
  02|progs|5423|02|progs|5423
  03|marketing|6521|03|marketing|6521
  04|personnel|2365|04|personnel|2365
  05|production|9876|05|production|9876
  06|sales|1006|
            



uniq

~ Uniq simply fetches one copy of each line and writes it to the standard output. But the listed should be sorted.

  saarthak@DESKTOP-N01EJET:~$ cat shortlist
  01|accounts|6213
  01|accounts|6213
  02|progs|5423
  02|progs|5423
  03|marketing|6521
  03|marketing|6521

  saarthak@DESKTOP-N01EJET:~$ uniq shortlist
  01|accounts|6213
  02|progs|5423
  03|marketing|6521