Changes

Jump to: navigation, search

Tutorial5: Redirection

68 bytes removed, 17:39, 23 January 2020
Additional File Manipulation Commands
There are some additional regular file manipulation commands that you can use with redirection<br>(in addition to the other regular file manipulation commands introduced in week 2). These commands are displayed in the table below:
<table cellpadding="5"><tr><th style="border-bottom: 1px solid black;text-align:left;">Linux Command</th><th style="border-bottom: 1px solid black;text-align:left;">Purpose</th></tr><tr valign="top"><td>'''cut'''</td><td>Used to extract fields and characters from records. The option '''-c''' option is used to cut by a character or a range of characters. The '''-f''' option indicates the field number or field range to display (this may require using the '''-d''' option to indicate the field separator (delimiter).<br><br>''Examples:''<br>'''cut -f2 filename''' - extract 2nd field from all records in file, using tab as delimiter (default)<br>'''cut -d' ' -f2,5 filename''' - extract 2nd and 5th field, using space as delimiter<br>'''cut -d' ' -f1-3,5 filename''' - extract 1st through 3rd and 5th fields, using space as delimiter<br>'''cut -c3-5 filename''' - extract 3rd to 5th characters</td></tr><tr valign="top"><td>'''tr'''</td><td>used to translate characters to different characters.<br><br>''Examples:''<br>'''tr a A < filename''' - translate all characters "a" to "A"<br>'''tr "[a-z]" "[A-Z]" < filename''' - translate lowercase "a" through "z" to uppercase<br>'''tr "a-z" "A-Z" < filename''' - translate lowercase "a" through "z" to uppercase, different syntax (non-System V)<br>'''tr ':' ' ' < filename''' - translate all colons to spaces<br>'''tr ' ' '\n' < filename''' - translate all spaces to newline characters<br>'''tr 'abc' 'A' < filename''' - translate 'a', 'b', and 'c' to 'A', the last character in the "to" string repeats<br>tr 'a-f' '1-3' < filename - same as: tr 'abcdef' '123333' <br></td></tr><tr valign="top"><td>'''wc'''</td><td>displays various counts of the contents of a file<br><br>''Examples:''<br>'''wc -l filename''' - displays number of lines in file<br>'''wc -c filename''' - displays number of characters in file<br>'''wc -w filename''' - displays number of words in fil<br></td></tr></table>
===Piping (Using Pipes)===
13,420
edits

Navigation menu