Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-21-2007, 10:46 PM   #1
LQ Newbie
Registered: Mar 2005
Posts: 11

Rep: Reputation: 0
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!
Old 03-22-2007, 12:08 AM   #2
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 681Reputation: 681Reputation: 681Reputation: 681Reputation: 681Reputation: 681
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.
Old 03-22-2007, 12:13 AM   #3
LQ Newbie
Registered: Mar 2005
Posts: 11

Original Poster
Rep: Reputation: 0
Thanks for that!

This is what I came up with..

grep -v Suzana test | awk '{print $1,$3}'
Old 03-22-2007, 02:04 AM   #4
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927
/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



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
scripting telnet sessions, redirect issue farkus888 Solaris / OpenSolaris 4 03-03-2007 02:18 PM
shell scripting: "formatting" issue with text files eur0dad Programming 3 08-17-2006 10:50 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM
Linux Scripting Issue Kicking my Butt !!! steve_f60 Linux - General 1 04-29-2005 04:00 PM
Scripting issue. dolvmin Linux - Software 8 09-18-2003 10:28 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:03 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration