Question: Hello I'm trying to do something like this but it wont work, can you guys tell me help me out?

```
/usr/bin/mysql -B -r -h ******** -u******* -p****** -D***** \
    -e'SELECT `username`, `uid`, `gid`, `homedir` FROM `some_table`)' | \
        awk '{print $1":x:"$2":"$3"::"$4":/usr/sbin/nologin"}' >> /tmp/file1 ;
        awk '{print $1":"$5":13753:0:99999:7:::"}'>>/tmp/file2

```

Changing ";" to "&&" doesn't work either.
Both file1 and file2 is created, but only file1 contains data.
So basically what I want to do is using the same variables for two commands

Answer: 
When you want to run two different commands on the same incoming pipe data, you need to use an intermediate file:

```
TMPFILE="$(mktemp)"
/usr/bin/mysql -B -r -h ******** -u******* -p****** -D***** \
               -e'SELECT `username`, `uid`, `gid`, `homedir` FROM `some_table`)' >"$TMPFILE"
awk '{print $1":x:"$2":"$3"::"$4":/usr/sbin/nologin"}' <"$TMPFILE" >>/tmp/file1
awk '{print $1":"$5":13753:0:99999:7:::"}' <"$TMPFILE" >>/tmp/file2
rm -f "$TMPFILE"

```

But as [quanta writes](https://serverfault.com/questions/322594/double-awk-commands-in-same-pipe/322613#322613), you can ask a single `awk` instance to do both operations.
Your command as shown will never work, as processing is entirely sequential, and the output of mysql is already used up by the first awk statement.

I would simply move all that to a tiny bash script:

```
#!/bin/bash
mycmd="SELECT `username`, `uid`, `gid`, `homedir` FROM `some_table`"
while read -r username, uid, gid, homedir; do
printf "%s:x:%s:%s::%s:/usr/sbin/nologin" "$username" "$uid" "$gid" "$homedir" >> /tmp/file1
printf "%s:%s:13753:0:99999:7:::" "$username" "missing variable" >>/tmp/file2
done <(/usr/bin/mysql -B -r -h * -u* -p* -D* -e "$mycmd")

```

UNtested, visit the [Wooledge Wiki](http://mywiki.wooledge.org/BashGuide) for more bash magic than you knew existed :)