How to print last field ouput in Linux?

Hi All,

I am trying to print the dpkg -l command output each field using below script. But i am unable to print the entire data of the last column.
Can someone please help me in selecting the entire last column data.

Below is the Command output :

||/ Name                             Version               Architecture          Description
+++-================================-=====================-=====================-=====================================================================
ii  accountsservice                  0.6.45-1ubuntu1       amd64                 query and manipulate user account information
ii  acl                              2.2.52-3build1        amd64                 Access control list utilities
ii  acpid                            1:2.0.28-1ubuntu1     amd64                 Advanced Configuration and Power Interface event daemon
ii  adduser                          3.116ubuntu1          all                   add and remove users and groups
ii  amd64-microcode                  3.20191021.1+really3. amd64                 Processor microcode firmware for AMD CPUs
ii  apparmor                         2.12-4ubuntu5.1       amd64                 user-space parser utility for AppArmor
ii  apport                           2.20.9-0ubuntu7.9     all                   automatically generate crash reports for debugging
ii  apport-symptoms                  0.20                  all                   symptom scripts for apport

Below is my script :

while IFS= read -r line;

do
NAME=$(echo "$line"|awk  '{print $2}')

Description=$(echo "$line"|awk  '{print $5}')

echo -e "{\"'name'\":\"'"$name"'\",\"'Description'\":\"'"$Description"'\"
}"

done < filename

I am unable to print the entire data of description column.
Can someone please help me in getting the entire data ?

Your code is a little hard to read....

awk '{printf("NAME: %s   DESCRIPTION: %s \n", $5 $6 $7 $8 $9 $(10) } ' filename 

The $5 $6 ... part does not know how many words are the in input line. You may need to count past 10, I do not know. If a field is empty, it will not affect output.
Any field number beyond 9 can be referenced by $( nn ) where nn is two numbers, i.e., 10 --- 99. Modern awk may not need the () thing. So just use $57 or whatever you need

Thanks jim mcnamara for your reply,

But i am not sure about how many fields of data will be in description column. Is there any alternate way to get the data to a variable ?.

Hi
Try this

awk '/^[iu]/ {sub(/(\S+\s+){4}/, ""); print}'

Using awk multiple times in a shell loops leads to the question "why shell at all"? Try also

awk '{NM = $2; $1 = $2 = $3 = $4 = ""; printf "%-15s\t%s\n", NM, $0}' file
Name                   Description
                      
accountsservice        query and manipulate user account information
acl                    Access control list utilities
acpid                  Advanced Configuration and Power Interface event daemon
adduser                add and remove users and groups
amd64-microcode        Processor microcode firmware for AMD CPUs
apparmor               user-space parser utility for AppArmor
apport                 automatically generate crash reports for debugging
apport-symptoms        symptom scripts for apport

Why not shell only?
The shell's read command reads the remainder into the last given variable; that's exactly what is desired here.

while read x name x x description
do
  echo -e "{\"'Name'\":\"'"$name"'\",\"'Description'\":\"'"$description"'\"}"
done < filename