# awk help

**URL:** <https://community.unix.com/t/awk-help/366848>\
**Category:** Shell Programming and Scripting\
**Created:** [June 1, 2017, 11:05am UTC](https://community.unix.com/t/awk-help/366848 "2017-06-01T11:05:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mathew\_paul](https://community.unix.com/letter_avatar/mathew_paul/32/6_449c533f586939b6e5f246632a46421f.png) [@Mathew\_paul](https://community.unix.com/u/Mathew_paul)\
**Post date:** [June 1, 2017, 11:05am UTC](https://community.unix.com/t/awk-help/366848/1 "2017-06-01T11:05:30Z")

</div>

Hi All,

have a file with list of server information, using awk just generating command

need to print second command in next line

---------------------------------------------------------------------

```nohighlight
cat test.txt
mack
jack

```

```nohighlight
cat test.txt | awk -v hst=$(hostname) ' { if ($1 == "jack" && hst = "varprod09" ) print "true" "yes" } '

```

---------------------------------  
output

```nohighlight
trueyes

```

-----------  
desired output

```nohighlight
true
yes

```

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/6_449c533f586939b6e5f246632a46421f.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [June 1, 2017, 11:32am UTC](https://community.unix.com/t/awk-help/366848/2 "2017-06-01T11:32:00Z")

</div>

Lose the pipe if you have an input file

```nohighlight
awk -v hst=$(hostname) ' { if ($1 == "jack" && hst = "varprod09" ) 
     {print "true" 
       print "yes" } ' test.txt

```

You can also either of these two print statements:

```nohighlight
printf("%s\n%s\n","true, "yes")
print "true" "\n" "yes"

```

Note the a space acts to concatenate strings -  
`"foo" "foo2" -> foofoo2`

---

<div class="post-metadata">

**Author:** ![rdrtx1](https://community.unix.com/user_avatar/community.unix.com/rdrtx1/32/2721_2.png) [@rdrtx1](https://community.unix.com/u/rdrtx1)\
**Post date:** [June 1, 2017, 4:13pm UTC](https://community.unix.com/t/awk-help/366848/3 "2017-06-01T16:13:27Z")

</div>

also:  
`hst = "varprod09"`  
should be:  
`hst == "varprod09"`
