0

I have one script which is running and giving an csv file as output in the below format

25-02-2013          
RJ          
D204349194          
Pagamento Caixa                                                     0   
           256.31    -256.31    

But i need to align in the below format :

25-02-2013  RJ  D244728244  Pagamento Banco Brasil  0   403.25  -403.25

Means like in excel it should be divided into columns

please suggest me

1
  • 2
    What is the magic transformation that converts 256.31 to 403.25? Commented Feb 27, 2013 at 13:36

3 Answers 3

1

if you have column installed, try this line:

 awk '{printf $0}' file|column -t

for your example:

kent$  cat file
25-02-2013          
RJ          
D204349194          
Pagamento Caixa                                                     0   
           256.31    -256.31

kent$  awk '{printf $0}' file|column -t
25-02-2013  RJ  D204349194  Pagamento  Caixa  0  256.31  -256.31
Sign up to request clarification or add additional context in comments.

2 Comments

You must have trailing whitespace in your input file. Or you are using a different awk. Also, column does not work well if the input does not end in a newline (on OS X).
@WilliamPursell nice point! my awk is gnu awk 4. I checked input in question, there are trailing spaces. that's why I came up with printf $0. with " " is certainly safer.
0

First use tr to pull everything onto a single line and then use sed to split the single line based on a field. Try the following:

tr '\n' '\t' < file | sed -r 's/([0-9]{2}-[0-9]{2}-[0-9]{4})/\n\1/g'

This assumes that:

  • your file is tab delimited
  • the first field of each record is a date of the form dd-MM-yyyy
  • there are no other dates in a record except for the first field

Comments

0
awk '{$1=$1; printf $0 "  "}' input; echo

The $1=$1 squeezes whitespace on each line, and the echo emits a terminating newline.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.