200 likes | 318 Vues
Creating a new ASCII file. Output usually goes to screen Output can be redirected to a file using the output redirection operator > (greater than symbol). Syntax to Create an ASCII File. Syntax: [command] > filename Example: dir > classfile.txt
E N D
Creating a new ASCII file Output usually goes to screen Output can be redirected to a file using the output redirection operator >(greater than symbol)
Syntax to Create an ASCII File Syntax: [command] > filename Example: dir > classfile.txt Note: If the filename already exists, the file will be OVERWRITTEN. Outputredirection symbol
Appending to an Existing ASCII file Instead of overwriting a file, the new information can be added to the end of the existing file. Syntax: [command] >> filename Example: dir a: >> classfile.txt
View an ASCII file The contents of a file can be viewed from the command prompt using the TYPE command. Syntax: TYPE filename Examples: TYPE mypoem.txt TYPE A:\Abc\mypoem.txt TYPE A:\Abc\mypoem.txt > PRN TYPE A:\mypoem.txt > A:\poemcopy.txt
PRACTICE-TYPE Type in the following: • A:<enter> • DIR • DIR > classfile.txt • TYPE classfile.txt • DIR r* • DIR r* >> classfile.txt • TYPE classfile.txt (in a minute we will learn how to prevent the display from scrolling off the page)
Using Redirect to Print Output can be redirected to a printer Syntax: [command] > printer port Examples: dir a: > PRN dir a: > LPT1
PIPING and FILTERS The PIPE operator redirects the output of one DOS command to another command. It looks like this: | A FILTER is a DOS command that can modify the output of another DOS command. They are: • MORE • SORT • FIND
Input and the MORE filter Input does not have to come from the keyboard Input can come from a file instead The MORE filter can take this input and alter the output The filter MORE displays a text file a page at a time on the computer screen Syntax: [command] | MORE Example: TYPE A:\programmer.txt | MORE
Redirecting Input Using an ASCII Text File Windows XP lets you use MORE in another way Syntax: MORE < filename Example: MORE < SomeFile.txt
Yet Another Way to Use MORE In Windows XP, MORE can be used the same way as TYPE Syntax: MORE filename Example: MORE A:\resume1.txt
Recap of the MORE filter In Windows XP, you can get the same results by typing in each of the following: Type classfile.txt | More More < classfile.txt More classfile.txt
Practice MORE Type in the following: • TYPE classfile.txt • TYPE classfile.txt | MORE • MORE < classfile.txt • MORE classfile.txt
Sorting ASCII Text Files The content of an ASCII file can be sorted before it is displayed. The SORT filter accepts the input and sorts it before it is displayed. Syntax: SORT < filename Example: SORT < classfile.txt
SORT syntax without redirect The SORT can be used without redirecting input. Syntax: SORT filename Example: SORT classfile.txt
Reversing the Sort Order The SORT order can be reversed. Syntax: SORT /R < filename orSORT /R filename Examples: SORT /R < classfile.txt orSORT /R classfile.txt
PRACTICE-SORT Type in the following: • SORT classfile.txt • SORT /R classfile.txt
Searching the Contents of an ASCII File The FIND filter allows you to find information in a file SYNTAX: FIND “string” filename EXAMPLE: FIND “04” classfile.txt
FIND and IGNORE CASE switch To have the command “ignore case” add the ignore switch SYNTAX: FIND /I “string” filename EXAMPLE: FIND /I “DOG” classfile.txt
PRACTICE-SORT Type in the following: • FIND “04” classfile.txt • FIND “file” classfile.txt • FIND “file” /i classfile.txt • FIND “an” classfile.txt • FIND “an” classfile.txt /i