Issue while splitting a row of record

Hi,

I have one file with the following details,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Account_Id Date Id Balance
44 9 1000.00 30 15-10-2173 10 1000.00 42 15-10-2173 10 1200.00 53 01-01-2008 10 1200.00

I need to split up the values in to the respective fields as follows,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Account_Id Date Id Balance
44         9 1000.00 
30 15-10-2173  10 1000.00 
42 15-10-2173  10 1200.00 
53 01-01-2008  10 1200.00

Initially i used the following command to split up the 4 values.

awk 'BEGIN{RS=" "}{sub("\n","")}ORS=NR%4?RS:"\n"'inpFile >tempFile

But in some cases I will not get the exact 4 values in the input file as given above(date is missing in the first record).

At that time the above command is displaying the unexpected result.

Can anyone help me on this.

Thanks in advance..!

tr '.' '\n' <input>>output

---------- Post updated at 01:15 AM ---------- Previous update was at 01:04 AM ----------

Sorry i think this script leave 00.

cat you_file  | sed "s/\.00/.00\n/"  |awk '{
        if (NF > 4 )
        {
                conta=1;
                for (word=1;word <=NF; word++)
                {
                        if (conta == 5)
                        {
                                printf "\n"
                                conta=1;
                        }
                        printf $word " ";
                        conta+=1;

                }
        }
        else print $0
     }
   END { }'

Hi..
Thanks alot for your reply..

Here if am using the above code snippet, its giving the output like this,

Account_Id Date Id Balance
44         9 1000.00 n
30 15-10-2173  10 1000.00 
42 15-10-2173  10 1200.00 
53 01-01-2008  10 1200.00

'n' is coming after the balance amount.

Can you please check this.

sorry in my execution i don't obtain the 'n' character.
maybe your data-source file is diferent at the text you put ?

$more kk.txt 
Account_Id Date Id Balance
44 9 1000.00 30 15-10-2173 10 1000.00 42 15-10-2173 10 1200.00 53 01-01-2008 10 1200.00
$sh kk2.sh
Account_Id Date Id Balance
44 9 1000.00
30 15-10-2173 10 1000.00 
42 15-10-2173 10 1200.00
53 01-01-2008 10 1200.00 

Hi ..
I executed the same script as you given above.but then I am getting the report like,

```text
Account_Id Date Id Balance
44  9  1000.00n  30
15-10-2173  10  1000.00  42
15-10-2173  10  1200.00  53
01-01-2008  10  1200.00
```


Then I tried to execute this with one small change in your script, 
```text
sed "s/\.00/.00 \n/" |awk '{ (Just given a single space in between .00 and \n )
```


Then I am getting the result as follows,
Account_Id Date Id Balance
44  9  1000.00  n
30  15-10-2173  10  1000.00
42  15-10-2173  10  1200.00
53  01-01-2008  10  1200.00

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

$ cat file
Account_Id Date Id Balance
44 9 1000.00 30 15-10-2173 10 1000.00 42 15-10-2173 10 1200.00 53 01-01-2008 10 1200.00

The idea is to split fields in group of 4. If the second field of that group is not a date, offset the field order by one.

NR>1{
    for(i=1;i<=NF;i++){
        dummy=""
        # if every second field is a not a date
        if(i+n==(2+(j*4)) && $i !~ /^[0-9][0-9]-/){
            dummy="            "    # set space for missing date
            n+=1                    # offset fields order by one
        }
        sep=" "
        if(!((i+n)%4)){             # line break every 4 field
            sep="\n"
            j++
        }
        printf dummy $i sep
    }
}

Yield the following result:

$ awk -f aa.awk file
44             9 1000.00
30 15-10-2173 10 1000.00
42 15-10-2173 10 1200.00
53 01-01-2008 10 1200.00