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
Adding columns of two files chandra321 Shell Programming and Scripting 7 05-06-2009 12:11 PM
adding columns Kelam_Magnus Shell Programming and Scripting 12 02-10-2009 10:56 AM
Adding columns to a file figaro UNIX for Dummies Questions & Answers 5 07-21-2008 01:50 AM
comparing files - adding/subtracting/formating columns oabdalla Shell Programming and Scripting 7 06-13-2008 03:20 AM
Adding columns to excel files using Perl dolo21taf Shell Programming and Scripting 1 02-20-2008 07:13 AM

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 03-05-2008
dolo21taf dolo21taf is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 6
Perl: adding columns in CSV file with information in each

Hi Wise UNIX Crew,

I want to add 3 different columns to the file in which:

1. The first new column pulls in today's date and time
2. Second column one has a '0'
3. Third column has the word 'ANY' going down the column

If my file content is as follows:

"7","a","abc",123"
"8","b","cde","456"
"9","c","fgh","789"

This is what I want the file content to be:
"2008-04-03 10:33:08",0,ANY,"7","a","abc",123"
"2008-04-03 10:33:08",0,ANY,"8","b","cde","456"
"2008-04-03 10:33:08",0,ANY,"9","c","fgh","789"

Big brownie points in advance......and a bigger thanks

S
  #2 (permalink)  
Old 03-05-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,079
HI,

Speaking of Perl, i am a virgin, below is the AWK solution. Hope can help you somewhat.

Code:
d=`date '+ %y-%m-%d %H:%M:%S'`
nawk -v dd="$d" 'BEGIN{FS=","}
{
printf("\"%s\",0,\"ANY\",%s,%s,%s,%s\n",dd,$1,$2,$3,$4)
}' filename
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 07:03 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