LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Urgent (https://www.linuxquestions.org/questions/linux-newbie-8/urgent-865845/)

caliiluvv 03-01-2011 09:34 PM

Urgent
 
I have a big file called the game, and want to find all the lines that do NOT have the word "shozbot" in it, and I want to sort them alphabetically, and save that in a file called "squiggy". How would I do that in one line of commands?


Thnks

gilead 03-01-2011 09:42 PM

Sorry, but it's hard to take your post seriously - with a subject of urgent and a task that sounds like it was made up... What have you done so far and what specific problem are you having?

win32sux 03-02-2011 07:29 AM

Seriously, pick a more appropriate title for your post next time.

As for the command, here's a basic example (you'll need to add options depending on your requirements):
Code:

grep -v shozbot game.txt | sort > squiggy.txt

devUnix 03-02-2011 07:45 AM

Win32sux has answered your question.

I give you some explanation here.

Code:

grep -v "pattern" fileName
prints lines that do not caontain the "pattern". If the "pattern" is not found at all then all the lines are printed.

Remove the -v option and it will print only those lines that contain at least one match of the "pattern".

So,

Code:

grep -v "shozbot" game
will print any line that does not contain "shozbot".

Next, we pipe this output to the sort command which displays the sorted lines:

Code:

grep -v "shozbot" game | sort
Finally, we redirect the sorted output to a named file:

Code:

grep -v "shozbot" game | sort > squiggy
Check it out!


All times are GMT -5. The time now is 10:06 AM.