Angus
Angus

Reputation: 12631

use of grep commands in unix

I have a file and i want to sort it according to a word and to remove the special characters. The grep command is used to search for the characters

-b Display the block number at the beginning of each line. 
-c Display the number of matched lines. 
-h Display the matched lines, but do not display the filenames. 
-i Ignore case sensitivity. 
-l Display the filenames, but do not display the matched lines. 
-n Display the matched lines and their line numbers. 
-s Silent mode. 
-v Display all lines that do NOT match. 
-w Match whole word 

but How to use the grep command to do the file sort and remove the special character and number.

Upvotes: 0

Views: 866

Answers (2)

Shiplu Mokaddim
Shiplu Mokaddim

Reputation: 57690

The following command would do it.

 sort FILE  | tr -d 'LIST OF SPECIAL CHARS' > NEW_FILE

Upvotes: 2

Philluminati
Philluminati

Reputation: 2789

grep searches inside all the files to find matching text. It doesn't really sort and it doesn't really chop and change output. What you want is probably to use the sort command

sort <filename>

and the output sent to either the awk command or the sed command, which are common tools for manipulating text.

sort <filename> | sed 's/REPLACE/NEW_TEXT/g'

something like above I'd imagine.

Upvotes: 2

Related Questions