Visit Our UNIX and Linux User Community


Change file output format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Change file output format
# 1  
Old 12-03-2009
Change file output format

I have a file which has following contents

Code:
usmtnz-dinfsi19
62
61
18400
18800
99.7
usmtnz-dinfsi19
62
61
18400
18800
99.7

i want the o/p to be like
Code:
date 
usmtnz-dinfsi19   62   61    18400    18800    99.7 
date 
usmtnz-dinfsi19   64   65    20000    23000    88.9 
date 
.........n

how can i do that ?
# 2  
Old 12-03-2009
code:-

Code:
gawk '(NR%6){s=s" "$0 ;next} 
((NR+1)%6){"date"|getline d ; print d"\n"s" " $0 ; s="" }
'  infile.txt > outfile.txt

SmilieSmilieSmilieSmilie

---------- Post updated at 18:07 ---------- Previous update was at 18:04 ----------

or if you want the date format to be YYYY-MM-DD

Code:
nawk '(NR%6){s=s" "$0 ;next}
((NR+1)%6){"date  '+%Y-%m-%d'"|getline d ; print d"\n"s" " $0 ; s="" }
' file.txt > out.txt

SmilieSmilieSmilieSmilie
# 3  
Old 12-03-2009
Cool ,thank you very much now is it possible to use arithmetic operations on the output like


Code:
64   65    20000/1000    23000/1000    100 - 88.9

And one more thing can you please refer to a awk,nawk link where i can learn it ?
# 4  
Old 12-03-2009
just cuz it's a handy trick:

Code:
pr -l1 -t -6 a

( But seriously, the "date" command is going to be the same practically for everyline unless you're running a file with a zillion lines. What value does that provide?! )
# 5  
Old 12-03-2009
I didn't get what you wrote Smilie
# 6  
Old 12-04-2009
Code:
cat a.txt | paste - - - - - - | sed 'i\
        date
        '

# 7  
Old 12-08-2009
Thanx for the help

Previous Thread | Next Thread
Test Your Knowledge in Computers #301
Difficulty: Easy
Slackware was originally derived from the Software Linux System (SLS).
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Change the file format

gpio_rw = gpiochip162 audio_aplay = HDMI_0 audio_aplay = HDMI_1 audio_aplay = HDMI_2 graphic_xrandr_show = USB1 graphic_xrandr_show = USB2 graphic_xrandr_show = USB3 graphic_change_resolution = eDP1 gpio_rw = "gpiochip162" audio_aplay = "HDMI_0 HDMI_1 HDMI_2" graphic_xrandr_show =... (3 Replies)
Discussion started by: yanglei_fage
3 Replies

2. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

3. Shell Programming and Scripting

change output format using ksh

I have a script that reaches out to several systems and pulls back infomation in serveral files. I would like to take the infomation returned and reformat it so I can export it to excel. Below is current output: File1:item1:abc=1 File1:item2:efg File2:item1:ab=1 File2:item2:efg... (3 Replies)
Discussion started by: oldman2
3 Replies

4. Shell Programming and Scripting

howto change format of file?

Hi I have a file with this inside: How can I change it to: thanks a lot regards Israel. (3 Replies)
Discussion started by: iga3725
3 Replies

5. Shell Programming and Scripting

How can I change is output format by awk ?

Hello, Can you tell me how can I change this format by awk Input 0.2057422D-01 0.2463722D-01 -0.1068047D-02 Output 0.02057422 0.02463722 -0.001068047 Thanks wan (8 Replies)
Discussion started by: wanchem
8 Replies

6. Shell Programming and Scripting

change the output format

when i run the following command db2 list tablespaces Tablespaces for Current Database Tablespace ID = 0 Name = SYSCATSPACE State = 0x0000 Tablespace ID ... (3 Replies)
Discussion started by: lazydev
3 Replies

7. Shell Programming and Scripting

Dynamic output file generation using a input text file with predefined output format

Hi, I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format. Example: File.txt AP|{SSHA}VEEg42CNCghUnGhCVg== APVG3|{SSHA}XK|"password" AP3|{SSHA}XK|"This is test" .... etc --------- test.sh has... (1 Reply)
Discussion started by: hudson03051nh
1 Replies

8. Shell Programming and Scripting

To Change the file format Pls Help!!!

Hi All, I have a file like john::208:johnson john::208:mery john::208:test admin:*:1:johnson admin:*:1:test and wanna convert this as john::208:johnson,mery,test admin:*:1:johnson,test please help me to create a script for this thanks in advance John (4 Replies)
Discussion started by: johnsonpk
4 Replies

9. Shell Programming and Scripting

Change file format

Hi I have a file in the following format I have to convert this into four files , in the format as below. Data under Process SFA SUccess Section gets into file Named SFA_SUCCESS inthe following format ctr1,120 ctr2,1785 Data under Process SFA FAil gets into file Named SFA_Fail inthe... (2 Replies)
Discussion started by: sapics
2 Replies

10. UNIX for Advanced & Expert Users

Change format to file II

hi all... i have a big problem, and i hope someone can help me... i have a flat file, and its columns are separated by comma (CSV), something like this: 78 , 204R180 , 90/100 , 200001 , 12 ,200002 ,13 ..... 78 , 204R180 , 90/100 , 200001 , 29 ,200002 ,30 ..... 78 , 204R180 , 90/100 ,... (0 Replies)
Discussion started by: DebianJ
0 Replies

Featured Tech Videos