0

I have problem with echo command I need export data to csv but its empty file

#!/bin/bash 
while read domain
do
    ownname= whois $domain | grep -A 1 -i "Administrative Contact:" |cut -d ":" -f 2 | sed 's/ //' | sed -e :a -e '$!N;s/ \n/,/;ta'
    echo -e  "$ownname" >> test.csv 
done < dom.txt
beatgammit
  • 19,817
  • 19
  • 86
  • 129
  • 1
    You're running the `whois` command with the extra environment variable `ownname` set to an empty string. You need `ownname=$(...)` notation. – Jonathan Leffler Oct 24 '13 at 06:36

1 Answers1

3

You need to use command substitution to store command's output in a shell variable:

#!/bin/bash 
while read domain; do
    ownname=$(whois $domain | grep -A 1 -i "Administrative Contact:" |cut -d ":" -f 2 | sed 's/ //' | sed -e :a -e '$!N;s/ \n/,/;ta')
    echo -e  "$ownname" >> test.csv
done

PS: I haven't tested all the piped commands.

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • 2
    It is [Command Substitution](http://www.gnu.org/software/bash/manual/bash.html#Command-Substitution), not [Process Substitution](http://www.gnu.org/software/bash/manual/bash.html#Process-Substitution). – Jonathan Leffler Oct 24 '13 at 06:35