LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 03-21-2007, 10:46 PM   #1
szahri
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
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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
szahri
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
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

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


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:30 PM.

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