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 Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
replace the column values. charandevu Shell Programming and Scripting 6 04-02-2008 02:21 AM
how to read the column and print the values under that column gemini106 Shell Programming and Scripting 6 03-28-2008 07:05 AM
How to check Null values in a file column by column if columns are Not NULLs Mandab Shell Programming and Scripting 7 03-15-2008 09:57 AM
Capturing the values of column in one parameter mgirinath Shell Programming and Scripting 5 06-14-2006 01:43 PM
Replace 10th column with a new column--- Terriblly hurry ahmedwaseem2000 Shell Programming and Scripting 2 09-06-2005 01:10 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-06-2007
sumeet sumeet is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 33
replace a column values with the first value in column

Hi All,

I have a file which has data in following format:

"Body_Model","2/1/2007","2/1/2007"
"CSCH74","0","61"
"CSCS74","0","647"
"CSCX74","0","3"
"CSYH74","0","299"
"CSYS74","0","2514"
"CSYX74","0","3"
"Body_Model","3/1/2007","3/1/2007"
"CSCH74","0","88"
"CSCS74","0","489"
"CSCX74","0","4"
"CSYH74","0","386"
"CSYS74","0","1871"
"CSYX74","0","4"

I want to have to convert to get following :

"Body_Model","2/1/2007","2/1/2007"
"CSCH74","2/1/2007","61"
"CSCS74","2/1/2007","647"
"CSCX74","2/1/2007","3"
"CSYH74","2/1/2007","299"
"CSYS74","2/1/2007","2514"
"CSYX74","2/1/2007","3"
"Body_Model","3/1/2007","3/1/2007"
"CSCH74","3/1/2007","88"
"CSCS74","3/1/2007","489"
"CSCX74","3/1/2007","4"
"CSYH74","3/1/2007","386"
"CSYS74","3/1/2007","1871"
"CSYX74","3/1/2007","4"

Can any of Unix Gurus help me.

Thanks
Sumeet
  #2 (permalink)  
Old 02-06-2007
Glenn Arndt's Avatar
Glenn Arndt Glenn Arndt is offline Forum Advisor  
Anomalous Lurker
  
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
Code:
awk 'BEGIN { FS="," }
 $1 ~ /Body_Model/ { mydate=$2; print; next }
 { print $1, mydate, $3 }' file.txt
  #3 (permalink)  
Old 02-06-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Quote:
Originally Posted by Glenn Arndt
Code:
awk 'BEGIN { FS="," }
 $1 ~ /Body_Model/ { mydate=$2; print; next }
 { print $1, mydate, $3 }' file.txt
Glenn,
you forgot to assign the OFS.
Code:
nawk 'BEGIN { FS=OFS="," }
 $1 ~ /Body_Model/ { mydate=$2; print; next }
 { print $1, mydate, $3 }' file.txt
  #4 (permalink)  
Old 02-06-2007
Glenn Arndt's Avatar
Glenn Arndt Glenn Arndt is offline Forum Advisor  
Anomalous Lurker
  
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
Thumbs up

Oops! Thanks for catching that.
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:45 PM.


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