The UNIX and Linux Forums  


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
Retrieve 5th Field to Last Field !! jobbyjoseph UNIX for Dummies Questions & Answers 3 05-16-2007 04:20 AM
select last field from a file kykyboss Shell Programming and Scripting 3 11-14-2006 10:15 AM
Moving Part of a field to another field using AWK rjsha1 Shell Programming and Scripting 5 08-04-2006 06:39 AM
add increment field when first field changes azekry Shell Programming and Scripting 2 11-14-2005 04:21 PM
Help me to select the flavour collins UNIX for Advanced & Expert Users 2 10-20-2004 07:17 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-09-2008
Satyak Satyak is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 85
Post select a particular field

hi
i have a file


wwww-qqq.eee [123343333] ksdklfsdf adm,as.d,am sdsdlasdjl sadsadasda
wwww-qqq.eee [123343331] ksdklfsdf adm,as.d,am sdsdlasdjl sadsadasda
wwww-qqq.eee [123343332] ksdklfsdf adm,as.d,am sdsdlasdjl sadsadasda
wwww-qqq.eee [123343333] ksdklfsdf adm,as.d,am sdsdlasdjl sadsadasda
wwww-qqq.eee [123343334] ksdklfsdf adm,as.d,am sdsdlasdjl sadsadasda

from the above file i need to extract secon field [123343333] and print that line to a separate file

please help

thanks
Satya
  #2 (permalink)  
Old 10-09-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:
cut -f2 file >newfile

  #3 (permalink)  
Old 10-09-2008
a2156z a2156z is offline
Users Awaiting Email Confirmation
  
 

Join Date: Oct 2008
Posts: 30
awk '{print $2,NR}' "$file_name" | cut -d'[' -f2 | tr -d ']' > "$backfile"

Last edited by a2156z; 10-09-2008 at 05:07 AM..
  #4 (permalink)  
Old 10-09-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
Yeah, you could cut on [ if you want to remove the brackets. The awk is rather unnecessary, though.


Code:
cut -d'[' -f2 file | cut -d']' -f1 >newfile

  #5 (permalink)  
Old 10-09-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,331
Or just with awk:


Code:
awk 'BEGIN{FS="\[|\]"}{print $2}' file

Regards
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:53 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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