mahesh
mahesh

Reputation: 1

need to align the csv file in proper format

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

Upvotes: 0

Views: 1570

Answers (3)

William Pursell
William Pursell

Reputation: 212238

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

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

Upvotes: 0

dogbane
dogbane

Reputation: 274562

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

Upvotes: 0

Kent
Kent

Reputation: 195039

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

Upvotes: 1

Related Questions