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
moving apache part 2 marinob007 UNIX for Dummies Questions & Answers 12 12-21-2007 03:11 PM
Extract Part of string from 3rd field $3 using AWK stakuri Shell Programming and Scripting 4 10-10-2007 12:28 PM
Retrieve 5th Field to Last Field !! jobbyjoseph UNIX for Dummies Questions & Answers 3 05-16-2007 03:20 AM
Moving part of Text in a file mgirinath Shell Programming and Scripting 4 02-06-2006 06:04 PM
add increment field when first field changes azekry Shell Programming and Scripting 2 11-14-2005 04:21 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 08-04-2006
rjsha1 rjsha1 is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 33
Moving Part of a field to another field using AWK

Hi there,
I have a comma seperated file with nine fields

the fields are

rerate: "numberTX",field2,field3,field4,field5.....


I want to do this to the file

reate: "field5TX",field2,field3,field4,field5


I know I can do this using AWK, but the thing giving me fits is that I need to keep the first part of thr first field there. Anyone got any ideas how I would do this ????
  #2 (permalink)  
Old 08-04-2006
rjsha1 rjsha1 is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 33
Hi guys,
This is what I have so far

nawk 'BEGIN {OFS=","} $1="Rerate: "$15 {print} ' robtest.txt >robawk.txt2

but it is placing a comma after Rerate: - what am I doing wrong
  #3 (permalink)  
Old 08-04-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,420
Try !
Code:
nawk 'BEGIN {FS="," ;OFS=","} {$1="Rerate: "$5 ;print} ' robtest.txt >robawk.txt2

Jean-Pierre.
  #4 (permalink)  
Old 08-04-2006
rjsha1 rjsha1 is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 33
Hi Jean-Pierre,

That's great.. However I have another question, what if the Field seperator is a " as opposed to a , ?????
  #5 (permalink)  
Old 08-04-2006
vish_indian vish_indian is offline
Registered User
  
 

Join Date: Jun 2006
Location: Delhi, India
Posts: 92
Quote:
what if the Field seperator is a " as opposed to a , ?????
echo "a\"b\"c" | awk -F'"' '{print $1,$2,$3}' " enclosed in ' '

or
echo "a\"b\"c" | awk -F"\"" '{print $1,$2,$3}' " enclosed in " ", preceeded by a \
  #6 (permalink)  
Old 08-04-2006
rjsha1 rjsha1 is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 33
Cheers vish - knew I was missing something - thanks guys for all your help.
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 10:16 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