How to cut a space from a string in a Unix shell script

I am reading a file and cutting a column based on some logic. My issue is I am not able to cut a column with space.

This is the code for testing –

st="1|alalhabad|up|tushar|kesarwani|90|   mls   k|19990|india|420|24|m"
HardErrorCheckColumnValue=`echo $st | cut -d'|' -f7`
echo $HardErrorCheckColumnValue

The output should be –

   mls   k

But I am getting-

mls   k

How do I make it not trim the leading or trailing spaces? It should give space, even if it contains only space.

Source: bash

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.