LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Scripting issue.. (https://www.linuxquestions.org/questions/linux-newbie-8/scripting-issue-539514/)

szahri 03-21-2007 11:46 PM

Scripting issue..
 
Hi all!
Im just starting to learn shell scripting...I hope you guy can help..

I have a test file that contains 400 rows of data.
Each row contains four columns, name, date_built, date_installed, date_commisioned. Each separated by space. What command do I need to select all rows in the file that dont contain the name Suzana, but only display the column name and date_installed?

Just a few hints would do or nudge in the right direction..thanks!

jschiwal 03-22-2007 01:08 AM

Look at the man pages for grep and cut. Use one command to filter out the lines you don't want, and pipe it to another commands the displays the columns you want.
You can also use awk instead, selecting lines that don't match Suzana and displaying the fields of interest.

szahri 03-22-2007 01:13 AM

Thanks for that!

This is what I came up with..

grep -v Suzana test | awk '{print $1,$3}'

Tinkster 03-22-2007 03:04 AM

/me coughs .... this looks familiar :)
http://www.linuxquestions.org/questi...d.php?t=539522

Do NOT post on the same (or closely related) topic more
than once.


Anyway, you're making it too complicated, and the use of
grep is pretty much never necessary if you're going to use
awk, anyway...

Code:

awk '!/Suzanna/ {print $1, $3}' test

Cheers,
Tink


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