nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Select specific rows

This is a discussion on Select specific rows within the Shell scripting forums, part of the Development/Scripting category; Hello, In a delimited flat file how to select the rows that have missed columns. Is there any unix commands ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 01-11-2007, 05:20 AM
Junior Member
User
 
Join Date: Dec 2006
Posts: 6
Rep Power: 0
c341
Default Select specific rows

Hello,
In a delimited flat file how to select the rows that have missed columns. Is there any unix commands
Thanks - Joe
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-11-2007, 05:28 PM
raj raj is offline
Contributors
User
 
Join Date: Jun 2005
Location: Hyderabad
Posts: 151
Rep Power: 4
raj is on a distinguished road
Default

row can be selected using various commands and while loop. you can use awk
Code:
cat filename | awk '{ print }'
you need to give me more information and examples so that i can help out ya
__________________
Raj
Linux rulz.
I have never turned back in my life ; I shall not do so today.. haha
Reply With Quote
  #3 (permalink)  
Old 01-14-2007, 12:58 AM
Junior Member
User
 
Join Date: Dec 2006
Posts: 6
Rep Power: 0
c341
Default

Hi Raj,

Example,

Col1 Col2 Col3 Col4
-----------------------
100|200|300|400
100|200|300
100|200|300|400
100|200

In the above example, I have 4 records in a flat file. The file has 4 columns.
In the rows if all the column values are present, that record will be selected without any problem.

I want to pick the rows 2 and 4 in the above example. How do I get that.

Thank You
Regards - Joe
Reply With Quote
  #4 (permalink)  
Old 01-15-2007, 03:38 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Ubuntu
Posts: 1,036
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Try awk as follows
Code:
cat file | awk -F'|' '{ if ( NF == 4 ) print }'
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
  #5 (permalink)  
Old 01-17-2007, 09:22 PM
Junior Member
User
 
Join Date: Dec 2006
Posts: 6
Rep Power: 0
c341
Default

Hello,
How do I implement this for a tab delimited file.
In Unix command how to provide tab as delimiter instead of '|'
Thanks - Joe
Reply With Quote
  #6 (permalink)  
Old 01-18-2007, 12:05 AM
Junior Member
User
 
Join Date: Dec 2006
Posts: 6
Rep Power: 0
c341
Default

Hello,
I got the answer for ta delimited ('\t')

Now, I want to get the result with the row numbers.

Example:

100 200 300 400
200 300 400
300 400 500 600

Result;

1 100 200 300 400
3 300 400 500 600

Thanks - Joe
Reply With Quote
  #7 (permalink)  
Old 01-18-2007, 03:04 AM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
My distro: Debian GNU/Linux
Posts: 482
Rep Power: 5
monk will become famous soon enough monk will become famous soon enough
Default

Quote:
Originally Posted by c341
Now, I want to get the result with the row numbers.
Try
Code:
cat file | awk -F'\t' '{ if ( NF == 2 ) print }'
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
match the columns of 2 files and merge common rows piyali_biobase Shell scripting 0 11-05-2007 07:34 PM
Linux shutdown computer specific time chiku Linux software 1 04-27-2007 05:53 PM
Mysql how to specify select columns raj Databases servers 2 12-19-2006 02:23 AM
How can I get some specific characters of dd command output warren Shell scripting 2 05-24-2006 04:59 PM
Script to extract a specific row of data ricc Shell scripting 1 11-15-2005 03:29 PM


All times are GMT +5.5. The time now is 06:01 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36