Is it possible to use a variable to do the line addressing for a sed command? I have a list of email addresses and am trying to access them one line at a time to store them in a variable. I need the first portion of the address (up to the @) to use as a filename, then I need to append the entire address to that newly created file, and finally append a generic message to each of the created files. Here is what I have:

FILE="emails"
foo=`grep -Enc .*@ $FILE`
for (( c=1; c<=foo; c++ ))
do
  NAME=`cat $FILE | sed -r '${c} s/(.*)@.*/\1/'`
  ADDRESS=`cat $FILE | sed -r "s/(.*@.*)/\1/"`
  touch $NAME
  echo $ADDRESS >> $NAME
done

As you can see, I would like to use the $c variable for my line number addressing. I'm pretty new to BASH so any help is greatly appreciated. Thanks in advance!

Solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.