1

I'm using rhel7 and trying to print my output from shadow for example to be like this :

test1 !!
test2 !!
test3 *

I am running this command:

i=`cat /home/mydir/shadow1 |awk -F ':' '{print $1,$2}' `

When I do echo $i, it will print the output in 1 line:

test !! test2 !! test3 *

Can anyone advice how should I modify my '{print $1,$2}' so that it will print a new line?

3 Answers3

0

Your awk print-statement is all fine.

Use quotes for echo:

echo "$i"
0

The question is clear. This problem can be approached in different ways. Not sure what the intention is but you can use for example the following:

while IFS=: read -r user stat _; do echo "$user" "$stat"; done < /etc/shadow

If you want to store the whole output of awk you could use something like this:

 var=$(awk -F: '{print $1,$2}' /etc/shadow)

You'd then just need to echo "$var" to print the results.

0

Instead of echo $i, try using:

echo -e "$i\n"

This adds a line break at the end of the line.

Hope it helps.