Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

c  

 
Cut :-

To extract data from each line of a text file

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 :-

-c characterlist À specify a list of characters to be cut from each


line

-f fieldlist À Specify a list of fields to be cut from each line.

-d character À To override the character to be interpreted


as the field delemiton.

-s À To suppress lines that do not hr the specified


delimiter character.

Ex :-

1 Jf you want to extract the first field,

cut ʹf1 file1

2 if you want to cut the chars 2 to 6 ,


cut ʹc2 -5 file1

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

ex : invokes the ex editor to edit one or more files

fmt : can be used to format files to a 72 characters line by default.

÷ 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 :

-b specify the position in bytes.

-s split a line after the last space at a position that is less than or equal to the
specified width

-w width specify the line width.

Ex : if you want to split the line at byte position 40

fold -w 40 file1 > file2;

if you do not want to split words,

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

- -t char À Modify the field seperator char from the default


value of the space.
Ex :-
1 Jf u want to join the 2 files & display the matching lines as well as the
Non-matching lines from the specified file.

- Join ʹa1 file1 file2

paste :-
can be used to paste lines from one or more files(one of them can be std. Jnput)

to the std. O/p, which can be redirected to a file.

- 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.

À u can specify multiple chars if u have multiple i/p files.


-s À merge subsequent lines from the i/p file for each i/p file, one at a time,
separated by the specified delimiter char.

Ex :-

÷ if u want to modify def. Separate filename tab to ͞/͟ =>


past -d ͞/͟ file1 file2

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.

- -A À Specify the sorting be done according to ASCJJ sequence.

- -c À check whether the specified files are sorted according to the


specified key & order.

- -d À sort according to dictionary order.

- -f À change all letters to uppercase before the sort.

- -i À Jgnore nondisplayable characters. For comparison.

- -m À merge presorted of files.

- -n À sort according to numerical valued.

- -o file À redirect the o/p to the specified file instead of to the std. O/p

- -r À sort the o/p in the reverse order of the specified order.

- -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

2 if you want to sort according to alphabetic order


sort ʹd 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.

-d À delete the specified chars.

-s À delete all but the first occurrence of the specified chars.

×      
 

À [char1-char2] À to specify a range of chars. Jncluding char1 & char2

À [char1*number] À to specify number occurrences of char.

À [char *] À to specify the use of as many occurrences as are needed

of character so that the i/p string of chars. To be


translated matches the o/p chars.

À [:charlist:] À to specify a list of chars. As the i/p or o/p string.

The charlist can be upper, lower, alph, space, digits,

& so on.

Ex :-

1 if u want to change the double quotes to spaces,


tr ͚\͛͟ ͚ ͚ < file1

2 if u want to change all lowercase letters to uppercase letter


tr [:lower:] [:upper:] <file1

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

Generate std o/p or another file.

÷ Also it is possible to compare only part of a line for comparison by using


Certain flags.

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

the i/p file.

-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

3 if u want to display the lines that appear only once in file1


uniq ʹu file1

Sed :-

To edit a file using a script


÷ in the script, u can specify commands to edit one or more lines according rules
specified as part of one or more commands.
Flag :-
-e command À use the specified sed comm.. to edit the file.

-f filename À use the filename as the editing script to edit the file.

-n À suppress messages from sed.

Ex :-

1 if u want to print the line no of the line in which a specified pattern is found,
sed ʹe ͞/sed/=͟ file1

You might also like