-   Linux - Newbie (
-   -   Scripting issue.. (

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

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


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


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