I have a file which has following contents
usmtnz-dinfsi19
62
61
18400
18800
99.7
usmtnz-dinfsi19
62
61
18400
18800
99.7
i want the o/p to be like
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 ?
code:-
gawk '(NR%6){s=s" "$0 ;next}
((NR+1)%6){"date"|getline d ; print d"\n"s" " $0 ; s="" }
' infile.txt > outfile.txt
:D:D:D:D
---------- Post updated at 18:07 ---------- Previous update was at 18:04 ----------
or if you want the date format to be YYYY-MM-DD
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
Cool ,thank you very much now is it possible to use arithmetic operations on the output like
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 ?
just cuz it's a handy trick:
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?! )
I didn't get what you wrote
cat a.txt | paste - - - - - - | sed 'i\
date
'
or better
cat a.txt | xargs -n 6 | sed 'i\
date
'
:D:D:D:D