Getting AWK error while transpose some message content

1

I trying to transpose below text into single line with pipe separated, i getting some error if text is start with number% , what is the issue, any other command is there

Sample content in txt file

PROMOTIONAL - ATL
36% Extra Money : NML 60=65(Rs.47.85 now, rest Rs.17.15 in 48hrs) + A&B @20p/m +  ACCC DD  for 11 day. 100=100 1 days.
2017-11-21
09:00 AM
10:00 PM
ENGLISH
OR
0.0
10

awk command using :

awk '{printf NR==1?$0:"|"$0}' text

Error:

PROMOTIONAL - ATLawk: (FILENAME=text FNR=2) fatal: not enough arguments to satisfy format string</br>
    `|36% Extra Money : NML 60=65(Rs.47.85 now, rest Rs.17.15 in 48hrs) + A&B @20p/m +  ACCC DD  for 11 day. 100=100 1 days.'
         ^ ran out for this one

Arun Binoy

Posted 2017-11-21T06:34:04.493

Reputation: 55

Answers

1

The problem is that the first argument to printf should be a format string. In format strings, percent signs are treated specially. To avoid the problem with your input containing a % sign, try:

$ awk '{printf "%s",(NR==1?"":"|")$0}' text
PROMOTIONAL - ATL|36% Extra Money : NML 60=65(Rs.47.85 now, rest Rs.17.15 in 48hrs) + A&B @20p/m +  ACCC DD  for 11 day. 100=100 1 days.|2017-11-21|09:00 AM|10:00 PM|ENGLISH|OR|0.0|10

Here, the first argument to printf, being the format string, is %s. The %s instructs awk to take the second argument and format it as a string. The second argument can include % or not, it doesn't matter.

Or, equivalently, we can use:

$ awk '{printf "%s%s",(NR==1?"":"|"),$0}' text
PROMOTIONAL - ATL|36% Extra Money : NML 60=65(Rs.47.85 now, rest Rs.17.15 in 48hrs) + A&B @20p/m +  ACCC DD  for 11 day. 100=100 1 days.|2017-11-21|09:00 AM|10:00 PM|ENGLISH|OR|0.0|10

John1024

Posted 2017-11-21T06:34:04.493

Reputation: 13 893