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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Getting month and changing format marringi UNIX for Dummies Questions & Answers 7 05-19-2008 11:42 AM
changing the format of date nasirgondal Post Here to Contact Site Administrators and Moderators 1 06-07-2006 10:37 PM
Changing the format of date nhatch UNIX for Dummies Questions & Answers 4 04-11-2006 07:17 AM
Changing date format Sabari Nath S Shell Programming and Scripting 5 12-06-2005 11:38 PM
Changing the date format Dream86 Shell Programming and Scripting 10 06-08-2005 10:35 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-30-2008
Registered User
 

Join Date: Jan 2007
Posts: 48
changing format

Dear Experts,

Currently my script is gereating the output like this as mentioned below.
8718,8718,0,8777
7450,7450,0,7483
5063,5063,0,5091
3840,3840,0,3855
3129,3129,0,3142
2400,2400,0,2419
2597,2597,0,2604
3055,3055,0,3078
4249,4249,0,4266
4927,4927,0,4957
8920,8920,0,8978
19567,19567,0,19675
15249,15249,0,15330
13930,13930,0,14015
13694,13694,0,13742
13066,13066,0,13122
12477,12477,0,12548
12791,12791,0,12855
13754,13754,0,13842
13181,13181,0,13259
12991,12991,0,13048
12435,12435,0,12484
13545,13545,0,13624
14584,14584,0,14656

But i want to put one more filed in the beginning which the hours from 0 to 23 and then i want to remove the comma "," separator by space " ". so please any boday can help me that how i can do this. below is the example what i need.

0 11280 11238 42 8310 278614712365
1 9452 9418 34 6524 316133393258
2 6913 6893 20 4479 181166977197
3 5707 5682 25 3252 81632013829
4 5427 5412 15 2647 46489111672
5 5267 5244 23 2074 44848549151
6 5232 5192 40 2190 43271031178
7 4870 4825 45 2867 41230177377
8 6221 6143 78 3666 45317367933
9 7338 7285 53 4372 49832797662
10 12494 12415 79 9675 21794650247
11 11257 11189 68 8416 22724861286
12 9372 9314 58 6843 21935582761
13 8494 8439 55 6190 22792627162
14 8486 8417 69 6550 25862616004
15 10179 10114 65 7130 27358047451
16 10067 10014 53 6600 26836305812
17 10574 10510 64 6824 26546313813
18 10509 10417 92 7389 28518610203
19 10356 10262 94 7934 29440052363
20 11865 11766 99 8859 31288108440
21 11570 11396 174 8481 29865106485
22 11416 11307 109 9080 33985893791
23 11855 11745 110 8707 35429158339


dont consider the values its different just to show u the format what i need.
please help me its urgent.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-30-2008
Registered User
 

Join Date: Jan 2008
Posts: 294
did you want to modify your current script to produce the desired output or write a new script to modify the output? Here is a perl solution until you clarify your requirements:

Code:
perl -pe 'BEGIN {$i = 0;} print $i++, " ", s/,/ /g;' inputfile > outputfile
Reply With Quote
  #3 (permalink)  
Old 01-30-2008
jaduks's Avatar
Registered User
 

Join Date: Aug 2007
Location: Assam,India
Posts: 141
Code:
$ awk -F "," '{print NR-1,$0}' shary | tr ',' ' '
And if you have fixed length of fields,

Code:
$ awk -F "," 'BEGIN{OFS=" "}{print NR-1,$1,$2,$3,$4}' shary
//Jadu
Reply With Quote
  #4 (permalink)  
Old 01-30-2008
Registered User
 

Join Date: Jan 2008
Posts: 294
I should have used tr/,/ / in my above suggestion too. Much more efficient than s/,/ /g
Reply With Quote
  #5 (permalink)  
Old 01-31-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,441
Code:
awk 'BEGIN{FS=",";OFS=" "}
{ $1=$1; print NR-1 , $0 }
' "file"
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:51 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0