Professional Documents
Culture Documents
Text Processing in OS
Text Processing in OS
Cut :-
can be used for a file that contains data records so that each line consist of one or
more fields separated by tab characters.
Flag :-
Ex :-
3 if you want to cut all chars in the first field up to the first 5 character, use the
following command.
4 Cut ʹd͟s͟ ʹs ʹf1 file1
÷ preserves the blank lines in the i/p file as well as the spacing between words.
÷ u can modify the line length using the width flag
Fold : can be used to generate multiple lines from a single line by splitting the line at the
specified position
÷ y def, the line length is 80 bytes.
Flag :
-s split a line after the last space at a position that is less than or equal to the
specified width
fold ʹw 40 ʹs file1>file2.
- :- can be used to merge 2 files (one can be std. Jnput to execute a third file (Which can be
std. O/p)
÷ each line in the file is merged on the basis of a field that has the same value in both
i/p files to create one line in the o/p file.
÷ The filed in each file are separated by either a space or the tab character.
÷
÷ -1 field or ʹj1 field À specify that the join should be made on the basis of
field in the first file.
÷ -2 field or ʹj2 field À specify that the join should be made on the basis
of the field in the second file.
÷ -e string À specify that blank fields in the o/p file be
replaced by the specified string.
÷ -o field.fieldnumber À specify that the o/p should consist of the specified
fields.
À u can specify multiple fields by separating them
with commands
paste :-
can be used to paste lines from one or more files(one of them can be std. Jnput)
- This comm. concatenates the line from each input file to the output file, separating
them by default with the tab character.
Flag :-
-d list À specify chars, that will be used to separate corresponding lines from
the i/p files in the o/p files.
Ex :-
Sort :-
Js used to sort one or more files in the specified order by the specified key.
Jt can also be used to merge files that hr already been sorted.
Flag :-
- -k key À specify the key on which to sort the specification for the key
inchides the starting field & column position & the end field
& col. Position.
- -o file À redirect the o/p to the specified file instead of to the std. O/p
- -u À create only one line in the o/p for lines that sort identically.
Ex :-
1 if you want to sort in the reverse order,
sort ʹr file1
tr :-
to translate or delete characters from std. J/p to generate std. O/p./
÷ translate specified chars in the i/p from the input to generate the output.
÷ Aelete specified chars in the i/p from the input to generate the output.
÷ Aelete all but the first occurrences of the specified chars.
Flag :-
-c À translate all but the specified chars using the specified new
characters.
×
& so on.
Ex :-
3 if u want to delete all the newline char ͚\n͛ from the file
tr ʹd ͚\n͛ <file1
4 if u want to delete all but the first occurrences of a space & replace the
space with a ʹ(hypen) tr ʹs ͚ ͚ ͚-͚ <file1
uNJ :-
Can be used to eliminate duplicate adjacent lines from a file or from std. J/p to
Flag :-
-c À precede each line with a number while displaying the o/p (the no.
specifies the no of recursences of the line in the i/p file).
-d À display only th elines that occur multiple times adjacent to each other in
-u À display only the lines that appears only once in the i/p file.
-s no. of characters
or
+noofchars À specify the no of chars from the start of a line that will be ignored
while comparing adjacent lines.
-no of fields
or
+no of fields À specify the no of fields from the start of a line that will be ignored
while comparing adjacent lines
Ex :-
1 if u want to find unique lines in file1
2 if u want to display only the duplicate line
uniq ʹd file1
Sed :-
-f filename À use the filename as the editing script to edit the file.
Ex :-
1 if u want to print the line no of the line in which a specified pattern is found,
sed ʹe ͞/sed/=͟ file1