SlideShare ist ein Scribd-Unternehmen logo
1 von 13
Introduction to Unix and OS
Module 3
Simple filters
Dr. Girisha G S
Dept. of CSE
SoE,DSU, Bengaluru
1
Agenda
Commonly used Filter commands
- pr
- head
- tail
- cut
- paste
- sort
- uniq
- tr
2
Filters
Filters are the commands which accept data from standard input
manipulate it and write the results to standard output
What are Filers?
- The filters can read data from standard input when used without a
filename as argument, and from the file otherwise
pr : paginating files
- Displays the specified files on the standard output in a paginated form.
- pr command adds suitable headers, footers and formatted text.
- pr adds five lines of margin at the top and bottom. The header shows the date and
time of last modification of the file along with the filename and page number.
Syntax:
pr option(s) filename(s)
3
Example:
Before using pr, here are the contents of a sample file named food:
Options
-k prints k (integer) columns
-h “header” to have a header of user’s choice
-d double spaces the output
-n will number each line and helps in debugging
$
4
Let’s use pr options to make a two-column report with the header “Restaurants.”
$
5
head – displaying the beginning of the file
- head command displays the top of the file.
- It displays the first 10 lines of the file by default
Option
-n num : Prints the first ‘num’ lines instead of first 10 lines
Example – 1: consider the file having name state.txt contains all the names of the
Indian states . Without any option, head displays only the first 10 lines of the file
specified.
syntax:
head [option] [filename]…[filename]
$ cat state.txt
Andhra Pradesh
Arunachal Pradesh
Assam
Bihar
Chhattisgarh
Goa
Gujarat Haryana
Himachal Pradesh
Jammu and Kashmir
Jharkhand
Karnataka
Kerala
Madhya Pradesh
Maharashtra
Manipur
Meghalaya
Mizoram
Nagaland
Odisha
Punjab
Rajasthan
Sikkim
Tamil Nadu
Telangana
Tripura
Uttar Pradesh
Uttarakhand
West Bengal
$ head state.txt
Andhra Pradesh
Arunachal Pradesh
Assam
Bihar
Chhattisgarh
Goa
Gujarat
Haryana
Himachal Pradesh
Jammu and Kashmir
6
10
lines
Example2: display first 5 lines of the file state.txt
$ head -n 5 state.txt
Andhra Pradesh
Arunachal Pradesh
Assam
Bihar
Chhattisgarh
7
$ cat state.txt
Andhra Pradesh
Arunachal Pradesh
Assam
Bihar
Chhattisgarh
Goa
Gujarat Haryana
Himachal Pradesh
Jammu and Kashmir
Jharkhand
Karnataka
Kerala
Madhya Pradesh
Maharashtra
Manipur
Meghalaya
Mizoram
Nagaland
Odisha
Punjab
Rajasthan
Sikkim
Tamil Nadu
Telangana
Tripura
Uttar Pradesh
Uttarakhand
West Bengal
First 5
lines
tail – displaying the end of a file
- tail command displays the end of the file.
- It displays the last 10 lines of the file by default
Option
-n num : Prints the last ‘num’ lines instead of first 10 lines
syntax:
tail [option] [filename]…[filename]
Example – 1: consider the file having name state.txt contains all the names of the Indian
states . Without any option, tail displays only the last 10 lines of the file specified.
$ tail state.txt
Odisha
Punjab
Rajasthan
Sikkim
Tamil Nadu
Telangana
Tripura
Uttar Pradesh
Uttarakhand
West Bengal
8
$ cat state.txt
Andhra Pradesh
Arunachal Pradesh
Assam
Bihar
Chhattisgarh
Goa
Gujarat Haryana
Himachal Pradesh
Jammu and Kashmir
Jharkhand
Karnataka
Kerala
Madhya Pradesh
Maharashtra
Manipur
Meghalaya
Mizoram
Nagaland
Odisha
Punjab
Rajasthan
Sikkim
Tamil Nadu
Telangana
Tripura
Uttar Pradesh
Uttarakhand
West Bengal
Last
10 lines
Example2: display last 3 lines of the file state.txt
$ tail -n 3 state.txt
Uttar Pradesh
Uttarakhand
West Bengal
- With +n option tail command prints the data starting from specified line number of the
file instead of end, where n represents the line no from where the selection should begin
$ tail +25 state.txt
Telangana
Tripura
Uttar Pradesh
Uttarakhand
West Bengal
Example: display the data starting from 25th line onwards
9
$ cat state.txt
Andhra Pradesh
Arunachal Pradesh
Assam
Bihar
Chhattisgarh
Goa
Gujarat Haryana
Himachal Pradesh
Jammu and Kashmir
Jharkhand
Karnataka
Kerala
Madhya Pradesh
Maharashtra
Manipur
Meghalaya
Mizoram
Nagaland
Odisha
Punjab
Rajasthan
Sikkim
Tamil Nadu
Telangana
Tripura
Uttar Pradesh
Uttarakhand
West Bengal
25th line
onwards
cut - select parts of a line
- cut command is used to cut fields or columns of the text from a file and display it to
standard output
Syntax:
Cut [options] [file]
options:
-c cut characters from a file
-f cut the fields from a file
-d used to specify the delimeter
Example: Let's say you have a file named data.txt which contains the following text:
$ cat data.txt
one two three four five
alpha beta gamma delta epsilon
To "cut" only the third field of each line, use the command:
$ cut -f 3 data.txt
three
gamma
10
Example 2: "cut" only the second-through-fourth field of each line
$ cut -f 2-4 data.txt
two three four
beta gamma delta
Example 3: output only the third-through-twelth character of every line of data.txt
$ cut -c 3-12 data.txt
e two thre
pha beta g
Unix Cut by delimiter
Example : To display values from 2nd column of file smartphones.tx t
The tab character is default delimiter for cut command and "-f" option is used to cut by a
delimiter. You can override delimiter by providing the "-d" option.
$ cat smartphones.txt
Model:Company:Price:Camera:4G
IPhone4:Apple:1000$:Yes:Yes
Galaxy:Samsung:900$:Yes:Yes
Optimus:LG:800$:Yes:Yes
Sensation:HTC:400$:Yes:Yes
IPhone4S:Apple:1100:Yes:Yes
N9:Nokia:400:Yes:Yes
$ cut -d: -f2 smartphones.txt
Company
Apple
Samsung
LG
HTC
Apple
Nokia 11
paste – pasting files
- paste command will paste the content of the file side by side
- Uses the tab as default delimiter
Example: consider two files file1, file2 and the task is to merge lines of these two files.
$ cat file1
unix
linux
solaris
$ cat file2
os
server
system
$ paste file1 file2
unix os
linux server
solaris system
Syntax:
paste [options] [file]
12
options
-d specify a list of delimiters
-s joins lines of a single file together
Example: Merge file using delimiter
$ paste -d “|” file1 file2
unix|os
linux|server
solaris|system
Example: join lines in a file1
$ paste -s file1
unix linux solaris
13

Weitere ähnliche Inhalte

Was ist angesagt?

Html text and formatting
Html text and formattingHtml text and formatting
Html text and formatting
eShikshak
 

Was ist angesagt? (20)

Strings in python
Strings in pythonStrings in python
Strings in python
 
Introduction to Unix
Introduction to UnixIntroduction to Unix
Introduction to Unix
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 
User and groups administrator
User  and  groups administratorUser  and  groups administrator
User and groups administrator
 
Unit 1 introduction to data structure
Unit 1   introduction to data structureUnit 1   introduction to data structure
Unit 1 introduction to data structure
 
Unix operating system architecture with file structure
Unix operating system architecture with file structure Unix operating system architecture with file structure
Unix operating system architecture with file structure
 
Vi editor
Vi   editorVi   editor
Vi editor
 
Tags in html
Tags in htmlTags in html
Tags in html
 
Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
Html text and formatting
Html text and formattingHtml text and formatting
Html text and formatting
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 
Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Web application architecture
Web application architectureWeb application architecture
Web application architecture
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
 

Ähnlich wie Unix - Filters

Unix lab manual
Unix lab manualUnix lab manual
Unix lab manual
Chaitanya Kn
 
Unit 8 text processing tools
Unit 8 text processing toolsUnit 8 text processing tools
Unit 8 text processing tools
root_fibo
 
Unix command
Unix commandUnix command
Unix command
Atul Pant
 
1) List currently running jobsANS) see currently runningcommand.pdf
1) List currently running jobsANS) see currently runningcommand.pdf1) List currently running jobsANS) see currently runningcommand.pdf
1) List currently running jobsANS) see currently runningcommand.pdf
amaresh6333
 

Ähnlich wie Unix - Filters (20)

Handling Files Under Unix.pptx
Handling Files Under Unix.pptxHandling Files Under Unix.pptx
Handling Files Under Unix.pptx
 
Handling Files Under Unix.pptx
Handling Files Under Unix.pptxHandling Files Under Unix.pptx
Handling Files Under Unix.pptx
 
Unix lab manual
Unix lab manualUnix lab manual
Unix lab manual
 
Lab 4 -Linux Files, Directories and Basic Commands Part-2.pptx
Lab 4 -Linux Files, Directories and Basic Commands Part-2.pptxLab 4 -Linux Files, Directories and Basic Commands Part-2.pptx
Lab 4 -Linux Files, Directories and Basic Commands Part-2.pptx
 
Unix Trainning Doc.pptx
Unix Trainning Doc.pptxUnix Trainning Doc.pptx
Unix Trainning Doc.pptx
 
Unit 8 text processing tools
Unit 8 text processing toolsUnit 8 text processing tools
Unit 8 text processing tools
 
Unix command
Unix commandUnix command
Unix command
 
Linux Command Line - By Ranjan Raja
Linux Command Line - By Ranjan Raja Linux Command Line - By Ranjan Raja
Linux Command Line - By Ranjan Raja
 
Spsl II unit
Spsl   II unitSpsl   II unit
Spsl II unit
 
Unix short
Unix shortUnix short
Unix short
 
08 text processing_tools
08 text processing_tools08 text processing_tools
08 text processing_tools
 
intro unix/linux 05
intro unix/linux 05intro unix/linux 05
intro unix/linux 05
 
Basic Linux Commands
Basic Linux CommandsBasic Linux Commands
Basic Linux Commands
 
Matlab: Procedures And Functions
Matlab: Procedures And FunctionsMatlab: Procedures And Functions
Matlab: Procedures And Functions
 
Procedures And Functions in Matlab
Procedures And Functions in MatlabProcedures And Functions in Matlab
Procedures And Functions in Matlab
 
Basic linux commands
Basic linux commandsBasic linux commands
Basic linux commands
 
Lnx
LnxLnx
Lnx
 
1) List currently running jobsANS) see currently runningcommand.pdf
1) List currently running jobsANS) see currently runningcommand.pdf1) List currently running jobsANS) see currently runningcommand.pdf
1) List currently running jobsANS) see currently runningcommand.pdf
 
SGN Introduction to UNIX Command-line 2015 part 2
SGN Introduction to UNIX Command-line 2015 part 2SGN Introduction to UNIX Command-line 2015 part 2
SGN Introduction to UNIX Command-line 2015 part 2
 
2.Utilities.ppt
2.Utilities.ppt2.Utilities.ppt
2.Utilities.ppt
 

Mehr von Dr. Girish GS

Mehr von Dr. Girish GS (14)

Unix- the process
Unix-  the processUnix-  the process
Unix- the process
 
unix- Sort, uniq,tr,grep
unix- Sort, uniq,tr,grepunix- Sort, uniq,tr,grep
unix- Sort, uniq,tr,grep
 
unix- the process states, zombies, running jobs in background
unix-  the process states, zombies, running jobs in backgroundunix-  the process states, zombies, running jobs in background
unix- the process states, zombies, running jobs in background
 
Customizing the unix environment
Customizing the unix environmentCustomizing the unix environment
Customizing the unix environment
 
File systems and inodes
File systems and inodesFile systems and inodes
File systems and inodes
 
Basic regular expression, extended regular expression
Basic regular expression, extended regular expressionBasic regular expression, extended regular expression
Basic regular expression, extended regular expression
 
Loop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progamLoop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progam
 
Logic instructions part 1
Logic instructions part 1Logic instructions part 1
Logic instructions part 1
 
Bcd arithmetic instructions
Bcd arithmetic instructionsBcd arithmetic instructions
Bcd arithmetic instructions
 
Bcd and ascii arithmetic instructions
Bcd and ascii arithmetic instructionsBcd and ascii arithmetic instructions
Bcd and ascii arithmetic instructions
 
Ascii arithmetic instructions
Ascii arithmetic instructionsAscii arithmetic instructions
Ascii arithmetic instructions
 
Rotate instructions
Rotate instructionsRotate instructions
Rotate instructions
 
Program control instructions
Program control instructionsProgram control instructions
Program control instructions
 
Memory interface
Memory interfaceMemory interface
Memory interface
 

KĂźrzlich hochgeladen

Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
dharasingh5698
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
sivaprakash250
 

KĂźrzlich hochgeladen (20)

Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 

Unix - Filters

  • 1. Introduction to Unix and OS Module 3 Simple filters Dr. Girisha G S Dept. of CSE SoE,DSU, Bengaluru 1
  • 2. Agenda Commonly used Filter commands - pr - head - tail - cut - paste - sort - uniq - tr 2
  • 3. Filters Filters are the commands which accept data from standard input manipulate it and write the results to standard output What are Filers? - The filters can read data from standard input when used without a filename as argument, and from the file otherwise pr : paginating files - Displays the specified files on the standard output in a paginated form. - pr command adds suitable headers, footers and formatted text. - pr adds five lines of margin at the top and bottom. The header shows the date and time of last modification of the file along with the filename and page number. Syntax: pr option(s) filename(s) 3
  • 4. Example: Before using pr, here are the contents of a sample file named food: Options -k prints k (integer) columns -h “header” to have a header of user’s choice -d double spaces the output -n will number each line and helps in debugging $ 4
  • 5. Let’s use pr options to make a two-column report with the header “Restaurants.” $ 5
  • 6. head – displaying the beginning of the file - head command displays the top of the file. - It displays the first 10 lines of the file by default Option -n num : Prints the first ‘num’ lines instead of first 10 lines Example – 1: consider the file having name state.txt contains all the names of the Indian states . Without any option, head displays only the first 10 lines of the file specified. syntax: head [option] [filename]…[filename] $ cat state.txt Andhra Pradesh Arunachal Pradesh Assam Bihar Chhattisgarh Goa Gujarat Haryana Himachal Pradesh Jammu and Kashmir Jharkhand Karnataka Kerala Madhya Pradesh Maharashtra Manipur Meghalaya Mizoram Nagaland Odisha Punjab Rajasthan Sikkim Tamil Nadu Telangana Tripura Uttar Pradesh Uttarakhand West Bengal $ head state.txt Andhra Pradesh Arunachal Pradesh Assam Bihar Chhattisgarh Goa Gujarat Haryana Himachal Pradesh Jammu and Kashmir 6 10 lines
  • 7. Example2: display first 5 lines of the file state.txt $ head -n 5 state.txt Andhra Pradesh Arunachal Pradesh Assam Bihar Chhattisgarh 7 $ cat state.txt Andhra Pradesh Arunachal Pradesh Assam Bihar Chhattisgarh Goa Gujarat Haryana Himachal Pradesh Jammu and Kashmir Jharkhand Karnataka Kerala Madhya Pradesh Maharashtra Manipur Meghalaya Mizoram Nagaland Odisha Punjab Rajasthan Sikkim Tamil Nadu Telangana Tripura Uttar Pradesh Uttarakhand West Bengal First 5 lines
  • 8. tail – displaying the end of a file - tail command displays the end of the file. - It displays the last 10 lines of the file by default Option -n num : Prints the last ‘num’ lines instead of first 10 lines syntax: tail [option] [filename]…[filename] Example – 1: consider the file having name state.txt contains all the names of the Indian states . Without any option, tail displays only the last 10 lines of the file specified. $ tail state.txt Odisha Punjab Rajasthan Sikkim Tamil Nadu Telangana Tripura Uttar Pradesh Uttarakhand West Bengal 8 $ cat state.txt Andhra Pradesh Arunachal Pradesh Assam Bihar Chhattisgarh Goa Gujarat Haryana Himachal Pradesh Jammu and Kashmir Jharkhand Karnataka Kerala Madhya Pradesh Maharashtra Manipur Meghalaya Mizoram Nagaland Odisha Punjab Rajasthan Sikkim Tamil Nadu Telangana Tripura Uttar Pradesh Uttarakhand West Bengal Last 10 lines
  • 9. Example2: display last 3 lines of the file state.txt $ tail -n 3 state.txt Uttar Pradesh Uttarakhand West Bengal - With +n option tail command prints the data starting from specified line number of the file instead of end, where n represents the line no from where the selection should begin $ tail +25 state.txt Telangana Tripura Uttar Pradesh Uttarakhand West Bengal Example: display the data starting from 25th line onwards 9 $ cat state.txt Andhra Pradesh Arunachal Pradesh Assam Bihar Chhattisgarh Goa Gujarat Haryana Himachal Pradesh Jammu and Kashmir Jharkhand Karnataka Kerala Madhya Pradesh Maharashtra Manipur Meghalaya Mizoram Nagaland Odisha Punjab Rajasthan Sikkim Tamil Nadu Telangana Tripura Uttar Pradesh Uttarakhand West Bengal 25th line onwards
  • 10. cut - select parts of a line - cut command is used to cut fields or columns of the text from a file and display it to standard output Syntax: Cut [options] [file] options: -c cut characters from a file -f cut the fields from a file -d used to specify the delimeter Example: Let's say you have a file named data.txt which contains the following text: $ cat data.txt one two three four five alpha beta gamma delta epsilon To "cut" only the third field of each line, use the command: $ cut -f 3 data.txt three gamma 10
  • 11. Example 2: "cut" only the second-through-fourth field of each line $ cut -f 2-4 data.txt two three four beta gamma delta Example 3: output only the third-through-twelth character of every line of data.txt $ cut -c 3-12 data.txt e two thre pha beta g Unix Cut by delimiter Example : To display values from 2nd column of file smartphones.tx t The tab character is default delimiter for cut command and "-f" option is used to cut by a delimiter. You can override delimiter by providing the "-d" option. $ cat smartphones.txt Model:Company:Price:Camera:4G IPhone4:Apple:1000$:Yes:Yes Galaxy:Samsung:900$:Yes:Yes Optimus:LG:800$:Yes:Yes Sensation:HTC:400$:Yes:Yes IPhone4S:Apple:1100:Yes:Yes N9:Nokia:400:Yes:Yes $ cut -d: -f2 smartphones.txt Company Apple Samsung LG HTC Apple Nokia 11
  • 12. paste – pasting files - paste command will paste the content of the file side by side - Uses the tab as default delimiter Example: consider two files file1, file2 and the task is to merge lines of these two files. $ cat file1 unix linux solaris $ cat file2 os server system $ paste file1 file2 unix os linux server solaris system Syntax: paste [options] [file] 12
  • 13. options -d specify a list of delimiters -s joins lines of a single file together Example: Merge file using delimiter $ paste -d “|” file1 file2 unix|os linux|server solaris|system Example: join lines in a file1 $ paste -s file1 unix linux solaris 13

Hinweis der Redaktion

  1. We use commands that filter data to select only the portion of data that we wish to view or operate on. t can be used to process information in powerful ways such as restructuring output to generate useful reports, modifying text in files and many other system administration tasks.
  2. Cut specified character or field from each line of stdin and print to stdout. Sort the lines in stdin, and print the result to stdout. Filters are programs that takes its input form from the std i/p, transforms it into a meaningful format, and then returns it as standard output.. A common use of filters is to modify output. Just as a common filter culls unwanted items, Unix filters can restructure output. docstore.mik.ua/orelly/unix3/lunix/ch05_02.htm Linux has a number of filters. Pr - Paginates files for printing. This command used to format the page style format file for printing, optionally in multiple columns. pr is a command used to paginate or columnate files for printing There are many options available with this command which help in making desired format changes on file The cat and more commands display the contents of a file, but if a file is to be printed then other information might need to be added to the output, such as a page number or a running header containing the filename. The pr command formats a file before displaying its contents and also prints the date, time, filename and page number at the top of every page.
  3. -k divides the data in to k columns -h assigns the header value as the report header -n denotes all lines with numbers
  4. The text is output in two-column pages. The top of each page has the date and time, header (or name of the file, if header is not supplied), and page number.
  5.  It shows you the top few lines of a specified file. It can be useful when you want a quick peek at a large file, as an alternative to opening the file with a text editor If you want to see what is in a file without looking at the whole file, you may find the head command useful
  6. It shows you the last few lines of a specified file.
  7. where n represents the line number from where the selection should begin.
  8. is used to select sections of text from each line of file. Basically the cut command slices a line and extracts the text. tool to extract parts of each line of a file. What 'cut' does is, it cuts out a set of bytes or character or fields from each row of the file. Select only the characters from each line as specified in LIST select only these fields on each line In this example, each of these words is separated by a tab character, not spaces. The tab character is the default delimiter of cut, select fields or columns from a line by specifying a delimiter
  9. , there may arise a situation wherein you have to merge lines of multiple files to create more meaningful/useful data. there exists a command y paste that does this for you the paste command merges lines of files
  10. Paste command uses the tab delimiter by default for merging the files. You can change the delimiter to any other character by using the -d option., which requires you to provide the delimiting character you want to use. You can merge the files in sequentially using the -s option.  By default, the paste command merges the files in parallel.