The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to extract only first column from the file selamba_warrior Shell Programming and Scripting 11 05-21-2008 02:52 AM
How to extract a column from two different files in AWK? solracq Shell Programming and Scripting 7 04-29-2008 06:21 AM
column extract help cvm Shell Programming and Scripting 1 04-24-2008 04:19 PM
Extract column data from File sudheshnaiyer UNIX for Dummies Questions & Answers 3 10-11-2007 09:52 PM
extract column based on name t27 UNIX for Dummies Questions & Answers 3 08-29-2007 01:04 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-22-2008
selamba_warrior selamba_warrior is offline
Registered User
  
 

Join Date: May 2008
Posts: 12
How to extract first column with a specific character

Hi All,

Below is the sample data of my files:

O|A|571000689|D|S|PNH|S|SI
sadm|ibscml1x|
I|A|571000689|P|S|PNH|S|SI
sadm|ibscml1x|
O|A|571000689|V|S|PNH|S|SI
sadm|ibscml1x|
S|C|CAM|D|S|PNH|R|ZOA|2004
bscml1x|
I|C|CAM|P|S|PNH|R|ZOA|2004
bscml1x|
O|C|CAM|V|S|PNH|R|ZOA|2004
bscml1x|

I need to extract the first column that only contain "I" only?

Please assists


Thanks
  #2 (permalink)  
Old 05-22-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Code:
sed -n 's/^\(I\).*/\1/p' file
By "extract", do you really mean print only the first column? If not, maybe you mean

Code:
grep '^I' file
  #3 (permalink)  
Old 05-22-2008
selamba_warrior selamba_warrior is offline
Registered User
  
 

Join Date: May 2008
Posts: 12
Dear era,

Thanks. It work.

Actually i'm looking to the first command:

sed -n 's/^\(I\).*/\1/p' file

Can u explain on this?
  #4 (permalink)  
Old 05-22-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
If the current line matches I at start of line (that's the caret ^), replace the whole line with just the part which matched (that's what the parentheses are for; they capture the match into \1) and print it.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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



All times are GMT -4. The time now is 03:29 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0