Changes

Jump to: navigation, search

Tutorial5: Redirection

2,271 bytes removed, 08:33, 17 January 2021
Additional File Manipulation Commands
===Additional File Manipulation Commands===
 Before proceeding, there are some additional regular file [[Image:manipulation -commands that you can use with redirection<br>(in addition to the other regular file manipulation commands introduced in week 2).  These png|thumb|right|250px|Additional commands are displayed in the table below: <table cellpadding="5" width="55%"><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 manipulate content 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) which is tab by default).<br><br>''Examples:''<br><span style="font-family:courier;font-weight:bold;">cut -f2 filename</span> - extract 2nd field from all records in file<br><span style="font-family:courier;font-weight:bold;">cut -d' ' -f2,5 filename</span> - extract 2nd and 5th field<br><span style="font-family:courier;font-weight:bold;">cut -d' ' -f1-3,5 filename</span> - extract 1st to 3rd and 5th fields<br><span style="font-family:courier;font-weight:bold;">cut -c3-5 filename</span> - 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><span style="font-family:courier;font-weight:bold;">tr "[a-ztext files]" "[A-Z]" < filename</span> - translate lower to upper case<br><span style="font-family:courier;font-weight:bold;">tr "a-z" "A-Z" < filename</span> - same as above (non-System V servers)<br><span style="font-family:courier;font-weight:bold;">tr Before proceeding, let':' ' ' < filename</span> - translate all colons to spaces<br><span style="font-family:courier;font-weight:bold;">tr ' ' '\n' < filename</span> - translate all spaces s look at some additional commands used to newline characters<br><br></td></tr><tr valign="top"><td><span style="font-family:courier;font-weight:bold;">wc</span></td><td>Displays various '''counts''' manipulate content of the contents of a filetext files.<br><br>''Examples:''<br><span style="font-family:courier;font-weight:bold;">wc -l filename</span> - displays number of lines in file<br><span style="font-family:courier;font-weight:bold;">wc -c filename</span> - displays number of characters in file<br><span style="font-family:courier;font-weight:bold;">wc -w filename</span> - displays number of words in fil<br></td></tr></table>
===Redirection (Standard Input, Standard Output, Standard Error)===
13,420
edits

Navigation menu