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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Cut the last field 435 Gavea Shell Programming and Scripting 9 03-17-2009 01:04 PM
Moving Part of a field to another field using AWK rjsha1 Shell Programming and Scripting 5 08-04-2006 05:39 AM
add increment field when first field changes azekry Shell Programming and Scripting 2 11-14-2005 04:21 PM
TTL field??? solvman UNIX for Advanced & Expert Users 11 10-12-2001 12:54 AM
awk sub-field? kristy UNIX for Dummies Questions & Answers 2 10-05-2001 04:07 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-15-2007
jobbyjoseph jobbyjoseph is offline
Registered User
  
 

Join Date: Apr 2006
Location: Mumbai
Posts: 21
Retrieve 5th Field to Last Field !!

I have a script which retrieves certain fields from a text file using awk. The delimiter used is white space.

cat /home/eis/boss/OPS|while read LINE
do
crdno=`echo $LINE | awk '{print $1}'`
atm=`echo $LINE | awk '{print $2}'`
seq=`echo $LINE | awk '{print $3}'`
amount=`echo $LINE | awk '{print $8}'`
rec=`echo "CARD NO:$crdno ATM ID:$atm AMOUNT:$amount SEQ:$seq"`
done
Problem now is that we have a new field added in the text file which has to be retrieved. This field has addresses as values and as such there are white spaces in this field in the addresses. The address field starts at position no. 8 and is the last field as such but due to the white spaces between the values in this field I cannot retrieve the 8th Field without losing out some portion of values due to the white space between them.
eg:
FIELD1 FIELD2 FIELD3 FIELD8
a 21 400 EVERGLADES 20/A
b 22 5000 FLIPSYDE-REGION
c 23 650 GREEN DAY ROCKS

I need to retrieve from the 8th Field to whatever is the last field. Any suggestions on the same ??

Regds,
Jobby
  #2 (permalink)  
Old 05-15-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,932
8th field to the last field

Code:
awk -F" " '{ for ( i=8; i<=NF; i++ ) { printf "%s", $i } print "\n" }' filename
  #3 (permalink)  
Old 05-16-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Quote:
I need to retrieve from the 8th Field to whatever is the last field. Any suggestions on the same ??
Code:
cut -d" " -f8- filename
  #4 (permalink)  
Old 05-16-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,422
Code:

awk ' { for ( i=1;i<8;i++ ){ $i=""}$0=$0;print }'  "file"
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:41 PM.


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