LInux Help

Closed
Bugz - Dec 8, 2008 at 06:14 AM
jipicy Posts 40842 Registration date Wednesday August 27, 2003 Status Moderator Last seen August 10, 2020 - Dec 8, 2008 at 12:26 PM
Hey, right I have a file that I have to edit.
I need to create a shell script that gets 3 types of data and places them into 3 files
And then pastes them into a new file that's formatted into neat columns.

The file I have to edit is

26/10/01
                26/10/01
                26/10/01
                27/10/01
                28/10/01
                29/10/01
                29/10/01
                29/10/01
                29/10/01
                29/10/01
                29/10/01
                01/11/01
                01/11/01
                01/11/01
                01/11/01
                01/11/01
                01/11/01
                01/11/01
                02/11/01
                02/11/01
                03/11/01
                03/11/01
                03/11/01
                03/11/01
                04/11/01
                         686856
                         STANDING ORDER
                         CREDIT
                         686849
                         653937
                         653938
                         686855
                         DIRECT DEBIT
                         DIRECT DEBIT
                         STANDING ORDER
                         CREDIT
                         686854
                         DIRECT DEBIT
                         DIRECT DEBIT
                         DIRECT DEBIT
                         STANDING ORDER
                         STANDING ORDER
                         STANDING ORDER
                         686858
                         DIRECT DEBIT
                         653940
                         686857
                         686859
                         CREDIT
                         653939
                                                 $70.00  
                                              $1,301.25  
                                                 $22.89CR
                                                $580.00  
                                                 $21.00  
                                                 $20.00  
                                                 $76.72  
                                                 $10.00  
                                                 $44.00  
                                                 $23.00  
                                              $1,830.66CR
                                                $988.00  
                                                 $17.50  
                                                 $20.00  
                                                 $27.00  
                                                 $50.00  
                                                 $15.00  
                                                $220.00  
                                                 $50.00  
                                                 $11.27  
                                                $354.04  
                                                $101.00  
                                                 $70.00  
                                                  $6.85CR
                                                 $21.00  
 
I have so far
grep '../../..' bank > datemod
grep '[$]' bank > amount
Which gets me the first list 'dates' and the third list 'amount'.

I know that I have to use a 'sed' cmd to get the second list ( the middle column in the file) but not sure on the parameters for sed to search. when I do it I get all the data.

Please can you help thank you
Related:

1 response

jipicy Posts 40842 Registration date Wednesday August 27, 2003 Status Moderator Last seen August 10, 2020 17
Dec 8, 2008 at 12:26 PM
Hi,

I hope that I understood everything :
[rep]$ cat bank
                26/10/01
                26/10/01
                26/10/01
                27/10/01
                28/10/01
                29/10/01
                29/10/01
                29/10/01
                29/10/01
                29/10/01
                29/10/01
                01/11/01
                01/11/01
                01/11/01
                01/11/01
                01/11/01
                01/11/01
                01/11/01
                02/11/01
                02/11/01
                03/11/01
                03/11/01
                03/11/01
                03/11/01
                04/11/01
                         686856
                         STANDING ORDER
                         CREDIT
                         686849
                         653937
                         653938
                         686855
                         DIRECT DEBIT
                         DIRECT DEBIT
                         STANDING ORDER
                         CREDIT
                         686854
                         DIRECT DEBIT
                         DIRECT DEBIT
                         DIRECT DEBIT
                         STANDING ORDER
                         STANDING ORDER
                         STANDING ORDER
                         686858
                         DIRECT DEBIT
                         653940
                         686857
                         686859
                         CREDIT
                         653939
                                                 $70.00
                                              $1,301.25
                                                 $22.89CR
                                                $580.00
                                                 $21.00
                                                 $20.00
                                                 $76.72
                                                 $10.00
                                                 $44.00
                                                 $23.00
                                              $1,830.66CR
                                                $988.00
                                                 $17.50
                                                 $20.00
                                                 $27.00
                                                 $50.00
                                                 $15.00
                                                $220.00
                                                 $50.00
                                                 $11.27
                                                $354.04
                                                $101.00
                                                 $70.00
                                                  $6.85CR
                                                 $21.00

[rep]$ sed -n '
s/^\s\+//g
\#/# w datemod
/\$/ w amount
\#/\|\$#! w second
' bank && paste datemod amount second > file && cat file

26/10/01        $70.00          686856
26/10/01        $1,301.25       STANDING ORDER
26/10/01        $22.89CR        CREDIT
27/10/01        $580.00         686849
28/10/01        $21.00          653937
29/10/01        $20.00          653938
29/10/01        $76.72          686855
29/10/01        $10.00          DIRECT DEBIT
29/10/01        $44.00          DIRECT DEBIT
29/10/01        $23.00          STANDING ORDER
29/10/01        $1,830.66CR     CREDIT
01/11/01        $988.00         686854
01/11/01        $17.50          DIRECT DEBIT
01/11/01        $20.00          DIRECT DEBIT
01/11/01        $27.00          DIRECT DEBIT
01/11/01        $50.00          STANDING ORDER
01/11/01        $15.00          STANDING ORDER
01/11/01        $220.00         STANDING ORDER
02/11/01        $50.00          686858
02/11/01        $11.27          DIRECT DEBIT
03/11/01        $354.04         653940
03/11/01        $101.00         686857
03/11/01        $70.00          686859
03/11/01        $6.85CR CREDIT
04/11/01        $21.00  653939

[rep]$ 
;-))
0