changing format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting changing format
# 1  
Old 01-31-2008
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.
# 2  
Old 01-31-2008
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

# 3  
Old 01-31-2008
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
# 4  
Old 01-31-2008
I should have used tr/,/ / in my above suggestion too. Much more efficient than s/,/ /g
# 5  
Old 01-31-2008
Code:
awk 'BEGIN{FS=",";OFS=" "}
{ $1=$1; print NR-1 , $0 }
' "file"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Changing filename format

i need and outline to write a script that takes and old format and convert to a new format example: tupac - changes.mp3 and converts all mp3 files to the format of tupac/changes.mp3 thanks for taking your time (1 Reply)
Discussion started by: domdom110
1 Replies

2. Shell Programming and Scripting

Changing Date Format

How can i make the date command output yesterday's date, current date and the date 4 days ago, in the following format: 2012-10-03 code: date +% ???? (3 Replies)
Discussion started by: SkySmart
3 Replies

3. Shell Programming and Scripting

Changing the date format

Hi all, I have a file with below data af23b|11-FEB-12|acc7 ad23b|12-JAN-12|acc4 as23b|15-DEC-11|acc5 z123b|18-FEB-12|acc1 I need the output as below:-(date in yyyymmdd format) af23b|20120211|acc7 ad23b|20120112|acc4 as23b|20111215|acc5 z123b|20120218|acc1 Please help me on this.... (7 Replies)
Discussion started by: gani_85
7 Replies

4. UNIX for Advanced & Expert Users

Changing the date format

Hi All, I am new to this forum, could any one help me out in resolving the below issue. Input of the flat file contains several lines of text for example find below: 5022090,2,4,7154,88,,,,,4/1/2011 0:00,Z,L,2 5022090,3,1,6648,88,,,,,4/1/2011 0:00,Z,,1 5022090,4,1,6648,88,,,,,4/1/2011... (0 Replies)
Discussion started by: av_sagar
0 Replies

5. Shell Programming and Scripting

changing the format of the list

I have a file such that List : a, b, c, d I want to list this as List a b c d however the trick is the number of arguments in the list is varies. There might be 0-7 variables . Can you help me? Please use code tags when posting data and code samples! (5 Replies)
Discussion started by: ozum
5 Replies

6. UNIX for Dummies Questions & Answers

Changing from Excel date format to MySQL date format

I have a list of dates in the following format: mm/dd/yyyy and want to change these to the MySQL standard format: yyyy-mm-dd. The dates in the original file may or may not be zero padded, so April is sometimes "04" and other times simply "4". This is what I use to change the format: sed -i '' -e... (2 Replies)
Discussion started by: figaro
2 Replies

7. Shell Programming and Scripting

Changing Date format

How to change a date stored in a variable to YYYYMMDD. Variable output is in DD-MON-YY,required format is 'YYYYMMDD' Thanks, Sud (1 Reply)
Discussion started by: sud
1 Replies

8. Shell Programming and Scripting

changing month in Mmm format to mm FORMAT

i have an variable mydate=2008Nov07 i want o/p as in variable mymonth=11 (i.e nov comes on 11 number month) i want some command to do this for any month without using any loop. plz help me (1 Reply)
Discussion started by: RahulJoshi
1 Replies

9. UNIX for Dummies Questions & Answers

Getting month and changing format

Hello, I would like to get todays moth and write it in this format: _06_ Any ideas? (7 Replies)
Discussion started by: marringi
7 Replies

10. Shell Programming and Scripting

Changing the date format

Hi, I know there is a Q/A section and lots of posts regarding date command here. I am sorry to start a new thread. I am very new to shell scripting (actually i am working on my first program), so please forgive my ignorance. I could not find an answer to my problem else where so i posted it... (10 Replies)
Discussion started by: Dream86
10 Replies
Login or Register to Ask a Question