awk for loop for each line in a file
Clash Royale CLAN TAG#URR8PPP
up vote
5
down vote
favorite
I need to figure out how to get loop through a text file and for every line take the fields of name , project #, and email, and replace them in a email template to be sent out.
So this is the text file called send.txt:
Project 1,Jack,Chen,06,12,test@cs.fiu.edu
Project 2,Emily,Weiss,06,12,eweiss@cs.fiu.edu
Project 3,Mary,Gonzalas,06,12,Mgonz@cs.fiu.edu
and this is the email template called Reminder.email:
Dear __FULLNAME__:
This is a kindly reminder that our __Project__ meeting will be held on today.
Best Regards,
CIS5027
So for every line in the text file I need to replace in this email template the fields of FULLNAME: , and Project . With the corresponding values which I can do for the first line, however I cannot do it for every line.
This is my script
#
!/bin/sh
#Start your code from here
date= date "+%m/%d/%y"
print $date
#The following line is to scan a file called Event-member.data and return any lines with todays date and save them to a file called sendtoday.txt
grep -n $(date +"%m,%d") Event-member.data > sendtoday.txt
#The following line is to remove the first to characters of the file created above sendtoday.txt and output that to a file called send.txt.
cat sendtoday.txt | sed 's/^..//' > send.txt
#This is where im having trouble. When storing the values for the variables below of name, email, project #. The value of NR==1 thus it never goes through the rest of the lines. I've tried different solutions but none seem to work.
p=$(awk -F ',' 'NR==1print $1' send.txt)
n=$(awk -F ',' 'NR==1print $2' send.txt)
l=$(awk -F ',' 'NR==1print $3' send.txt)
e=$(awk -F ',' 'NR==1print $6' send.txt)
echo $p $n $l $e
#This part is to replace the values in the email template using sed and save the modified template as sendnow.txt.
sed -e "s/__FULLNAME__:/ $n $l :/g;s/__Project__/ $p /g" Reminder.email > sendnow.txt
cat sendnow.txt
#Yet to be written ... send out modified email templates.
exit 0
########
This is the output it produces :
06/12/14
Project 1 Jack Chen test@cs.fiu.edu
Dear Jack Chen :
This is a kindly reminder that our Project 1 meeting will be held on today.
Best Regards,
CIS5027
As you see it did properly replace the fields but only for Jack Chen. There were 3 lines in the send.txt file so there must be 3 modified versions of the above template.
shell-script sed awk
add a comment |
up vote
5
down vote
favorite
I need to figure out how to get loop through a text file and for every line take the fields of name , project #, and email, and replace them in a email template to be sent out.
So this is the text file called send.txt:
Project 1,Jack,Chen,06,12,test@cs.fiu.edu
Project 2,Emily,Weiss,06,12,eweiss@cs.fiu.edu
Project 3,Mary,Gonzalas,06,12,Mgonz@cs.fiu.edu
and this is the email template called Reminder.email:
Dear __FULLNAME__:
This is a kindly reminder that our __Project__ meeting will be held on today.
Best Regards,
CIS5027
So for every line in the text file I need to replace in this email template the fields of FULLNAME: , and Project . With the corresponding values which I can do for the first line, however I cannot do it for every line.
This is my script
#
!/bin/sh
#Start your code from here
date= date "+%m/%d/%y"
print $date
#The following line is to scan a file called Event-member.data and return any lines with todays date and save them to a file called sendtoday.txt
grep -n $(date +"%m,%d") Event-member.data > sendtoday.txt
#The following line is to remove the first to characters of the file created above sendtoday.txt and output that to a file called send.txt.
cat sendtoday.txt | sed 's/^..//' > send.txt
#This is where im having trouble. When storing the values for the variables below of name, email, project #. The value of NR==1 thus it never goes through the rest of the lines. I've tried different solutions but none seem to work.
p=$(awk -F ',' 'NR==1print $1' send.txt)
n=$(awk -F ',' 'NR==1print $2' send.txt)
l=$(awk -F ',' 'NR==1print $3' send.txt)
e=$(awk -F ',' 'NR==1print $6' send.txt)
echo $p $n $l $e
#This part is to replace the values in the email template using sed and save the modified template as sendnow.txt.
sed -e "s/__FULLNAME__:/ $n $l :/g;s/__Project__/ $p /g" Reminder.email > sendnow.txt
cat sendnow.txt
#Yet to be written ... send out modified email templates.
exit 0
########
This is the output it produces :
06/12/14
Project 1 Jack Chen test@cs.fiu.edu
Dear Jack Chen :
This is a kindly reminder that our Project 1 meeting will be held on today.
Best Regards,
CIS5027
As you see it did properly replace the fields but only for Jack Chen. There were 3 lines in the send.txt file so there must be 3 modified versions of the above template.
shell-script sed awk
stackoverflow.com/questions/15945302/… this seems to solve your problem.
– Jasper
Jun 12 '14 at 8:27
add a comment |
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I need to figure out how to get loop through a text file and for every line take the fields of name , project #, and email, and replace them in a email template to be sent out.
So this is the text file called send.txt:
Project 1,Jack,Chen,06,12,test@cs.fiu.edu
Project 2,Emily,Weiss,06,12,eweiss@cs.fiu.edu
Project 3,Mary,Gonzalas,06,12,Mgonz@cs.fiu.edu
and this is the email template called Reminder.email:
Dear __FULLNAME__:
This is a kindly reminder that our __Project__ meeting will be held on today.
Best Regards,
CIS5027
So for every line in the text file I need to replace in this email template the fields of FULLNAME: , and Project . With the corresponding values which I can do for the first line, however I cannot do it for every line.
This is my script
#
!/bin/sh
#Start your code from here
date= date "+%m/%d/%y"
print $date
#The following line is to scan a file called Event-member.data and return any lines with todays date and save them to a file called sendtoday.txt
grep -n $(date +"%m,%d") Event-member.data > sendtoday.txt
#The following line is to remove the first to characters of the file created above sendtoday.txt and output that to a file called send.txt.
cat sendtoday.txt | sed 's/^..//' > send.txt
#This is where im having trouble. When storing the values for the variables below of name, email, project #. The value of NR==1 thus it never goes through the rest of the lines. I've tried different solutions but none seem to work.
p=$(awk -F ',' 'NR==1print $1' send.txt)
n=$(awk -F ',' 'NR==1print $2' send.txt)
l=$(awk -F ',' 'NR==1print $3' send.txt)
e=$(awk -F ',' 'NR==1print $6' send.txt)
echo $p $n $l $e
#This part is to replace the values in the email template using sed and save the modified template as sendnow.txt.
sed -e "s/__FULLNAME__:/ $n $l :/g;s/__Project__/ $p /g" Reminder.email > sendnow.txt
cat sendnow.txt
#Yet to be written ... send out modified email templates.
exit 0
########
This is the output it produces :
06/12/14
Project 1 Jack Chen test@cs.fiu.edu
Dear Jack Chen :
This is a kindly reminder that our Project 1 meeting will be held on today.
Best Regards,
CIS5027
As you see it did properly replace the fields but only for Jack Chen. There were 3 lines in the send.txt file so there must be 3 modified versions of the above template.
shell-script sed awk
I need to figure out how to get loop through a text file and for every line take the fields of name , project #, and email, and replace them in a email template to be sent out.
So this is the text file called send.txt:
Project 1,Jack,Chen,06,12,test@cs.fiu.edu
Project 2,Emily,Weiss,06,12,eweiss@cs.fiu.edu
Project 3,Mary,Gonzalas,06,12,Mgonz@cs.fiu.edu
and this is the email template called Reminder.email:
Dear __FULLNAME__:
This is a kindly reminder that our __Project__ meeting will be held on today.
Best Regards,
CIS5027
So for every line in the text file I need to replace in this email template the fields of FULLNAME: , and Project . With the corresponding values which I can do for the first line, however I cannot do it for every line.
This is my script
#
!/bin/sh
#Start your code from here
date= date "+%m/%d/%y"
print $date
#The following line is to scan a file called Event-member.data and return any lines with todays date and save them to a file called sendtoday.txt
grep -n $(date +"%m,%d") Event-member.data > sendtoday.txt
#The following line is to remove the first to characters of the file created above sendtoday.txt and output that to a file called send.txt.
cat sendtoday.txt | sed 's/^..//' > send.txt
#This is where im having trouble. When storing the values for the variables below of name, email, project #. The value of NR==1 thus it never goes through the rest of the lines. I've tried different solutions but none seem to work.
p=$(awk -F ',' 'NR==1print $1' send.txt)
n=$(awk -F ',' 'NR==1print $2' send.txt)
l=$(awk -F ',' 'NR==1print $3' send.txt)
e=$(awk -F ',' 'NR==1print $6' send.txt)
echo $p $n $l $e
#This part is to replace the values in the email template using sed and save the modified template as sendnow.txt.
sed -e "s/__FULLNAME__:/ $n $l :/g;s/__Project__/ $p /g" Reminder.email > sendnow.txt
cat sendnow.txt
#Yet to be written ... send out modified email templates.
exit 0
########
This is the output it produces :
06/12/14
Project 1 Jack Chen test@cs.fiu.edu
Dear Jack Chen :
This is a kindly reminder that our Project 1 meeting will be held on today.
Best Regards,
CIS5027
As you see it did properly replace the fields but only for Jack Chen. There were 3 lines in the send.txt file so there must be 3 modified versions of the above template.
shell-script sed awk
shell-script sed awk
edited Nov 17 at 20:55
Rui F Ribeiro
38.2k1475123
38.2k1475123
asked Jun 12 '14 at 7:51
S0urc3
28114
28114
stackoverflow.com/questions/15945302/… this seems to solve your problem.
– Jasper
Jun 12 '14 at 8:27
add a comment |
stackoverflow.com/questions/15945302/… this seems to solve your problem.
– Jasper
Jun 12 '14 at 8:27
stackoverflow.com/questions/15945302/… this seems to solve your problem.
– Jasper
Jun 12 '14 at 8:27
stackoverflow.com/questions/15945302/… this seems to solve your problem.
– Jasper
Jun 12 '14 at 8:27
add a comment |
3 Answers
3
active
oldest
votes
up vote
5
down vote
accepted
There is no reason to use awk
for this. You could do it directly in the shell using read
. The general format is read foo bar
which will save the first field as $foo
and the rest of each line as $bar
. So, in your case, you would do something like:
while IFS="," read p n l foo bar e; do
sed -e "s/__FULLNAME__:/ $n $l :/g;s/__Project__/ $p /g" Reminder.email;
done < file
The IFS
is the Input Field Separator which, when set to ,
reads comma delimited fields. This lets you take each field and store it in a variable. Note that I used two extra variables foo
and bar
. This is because each field needs its own variable name and you have 6 fields. If you only give 4 variable names, the 4th ($e
) will contain the fields 4 through last.
Now, there are various other syntax errors in your script. First of all the shebang line is wrong, you need #! /bin/sh
, there can't be a blank line between the #!
and the /bin/sh
. Also, in order to assign the output of a command to a variable, you need to use the var=`command`
or, preferably var=$(command)
format. Otherwise, the command itself as a string and not its output is assigned to the variable. Finally, print
is not what you think it is. You are looking for printf
or echo
. So, a better way to write your script would be:
#!/bin/sh
date=$(date "+%m/%d/%y")
echo $date
## The following line is to scan a file called Event-member.data
## and return any lines with todays date and save them to a file
## called sendtoday.txt
grep -n $(date +"%m,%d") Event-member.data > sendtoday.txt
## The following line is to remove the first to characters of the file
## created above sendtoday.txt and output that to a file called
## send.txt.
## I rewrote this to avoid the useless use of cat.
sed 's/^..//' sendtoday.txt > send.txt
## This is where you use read
while IFS="," read p n l foo bar e; do
sed -e "s/__FULLNAME__:/ $n $l :/g;s/__Project__/ $p /g" Reminder.email > sendnow.txt
cat sendnow.txt
## This is where you need to add the code that sends the emails. Something
## like this:
sendmail $e < sendnow.txt
done < send.txt
exit 0
########
This works like clockwork. Thank you so much for your help. I think this is the most concise answer. I will be seeking your help again in the future :-) .
– S0urc3
Jun 12 '14 at 14:52
add a comment |
up vote
3
down vote
You have used NR==1 condition NR==1print $1
. That means it will consider the first line of send.txt
. Use NR==2 condition to get for 2nd line and so on. OR use loop to go through all the lines like,
while read line
do
p=`echo $line | awk -F '.' 'print $1'`
n=`echo $line | awk -F '.' 'print $2'`
l=`echo $line | awk -F '.' 'print $3'`
e=`echo $line | awk -F '.' 'print $1'`
sed -e "s/__FULLNAME__:/ $n $l :/g;s/__Project__/ $p /g" Reminder.email > sendnow.txt
done<send.txt
This is the approach I wanted to take but couldn't get this to work out. The above IFS approach works good though. Thanks for your input. Ill try to test this again.
– S0urc3
Jun 12 '14 at 14:54
add a comment |
up vote
1
down vote
maybe wrap your script in something like
for i in $(cat send.txt); do echo "line: $i"; done
?
-1. Very bad idea I'm afraid. 1) That reads the entire line (kind of, see the next point) into$i
which does not help the OP. 2) You never want to dofor i in $(cat file)
, you should always usewhile read i; do ... ; done < file
instead. With the for loop, the line will be split on whitespace so$i
will beProject
, then1,Jack,Chen,06,12,test@cs.fiu.edu
for the first line. 3) This doesn't answer the question in any case since you don't address the actual issue the OP had.
– terdon♦
Jun 12 '14 at 8:51
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
There is no reason to use awk
for this. You could do it directly in the shell using read
. The general format is read foo bar
which will save the first field as $foo
and the rest of each line as $bar
. So, in your case, you would do something like:
while IFS="," read p n l foo bar e; do
sed -e "s/__FULLNAME__:/ $n $l :/g;s/__Project__/ $p /g" Reminder.email;
done < file
The IFS
is the Input Field Separator which, when set to ,
reads comma delimited fields. This lets you take each field and store it in a variable. Note that I used two extra variables foo
and bar
. This is because each field needs its own variable name and you have 6 fields. If you only give 4 variable names, the 4th ($e
) will contain the fields 4 through last.
Now, there are various other syntax errors in your script. First of all the shebang line is wrong, you need #! /bin/sh
, there can't be a blank line between the #!
and the /bin/sh
. Also, in order to assign the output of a command to a variable, you need to use the var=`command`
or, preferably var=$(command)
format. Otherwise, the command itself as a string and not its output is assigned to the variable. Finally, print
is not what you think it is. You are looking for printf
or echo
. So, a better way to write your script would be:
#!/bin/sh
date=$(date "+%m/%d/%y")
echo $date
## The following line is to scan a file called Event-member.data
## and return any lines with todays date and save them to a file
## called sendtoday.txt
grep -n $(date +"%m,%d") Event-member.data > sendtoday.txt
## The following line is to remove the first to characters of the file
## created above sendtoday.txt and output that to a file called
## send.txt.
## I rewrote this to avoid the useless use of cat.
sed 's/^..//' sendtoday.txt > send.txt
## This is where you use read
while IFS="," read p n l foo bar e; do
sed -e "s/__FULLNAME__:/ $n $l :/g;s/__Project__/ $p /g" Reminder.email > sendnow.txt
cat sendnow.txt
## This is where you need to add the code that sends the emails. Something
## like this:
sendmail $e < sendnow.txt
done < send.txt
exit 0
########
This works like clockwork. Thank you so much for your help. I think this is the most concise answer. I will be seeking your help again in the future :-) .
– S0urc3
Jun 12 '14 at 14:52
add a comment |
up vote
5
down vote
accepted
There is no reason to use awk
for this. You could do it directly in the shell using read
. The general format is read foo bar
which will save the first field as $foo
and the rest of each line as $bar
. So, in your case, you would do something like:
while IFS="," read p n l foo bar e; do
sed -e "s/__FULLNAME__:/ $n $l :/g;s/__Project__/ $p /g" Reminder.email;
done < file
The IFS
is the Input Field Separator which, when set to ,
reads comma delimited fields. This lets you take each field and store it in a variable. Note that I used two extra variables foo
and bar
. This is because each field needs its own variable name and you have 6 fields. If you only give 4 variable names, the 4th ($e
) will contain the fields 4 through last.
Now, there are various other syntax errors in your script. First of all the shebang line is wrong, you need #! /bin/sh
, there can't be a blank line between the #!
and the /bin/sh
. Also, in order to assign the output of a command to a variable, you need to use the var=`command`
or, preferably var=$(command)
format. Otherwise, the command itself as a string and not its output is assigned to the variable. Finally, print
is not what you think it is. You are looking for printf
or echo
. So, a better way to write your script would be:
#!/bin/sh
date=$(date "+%m/%d/%y")
echo $date
## The following line is to scan a file called Event-member.data
## and return any lines with todays date and save them to a file
## called sendtoday.txt
grep -n $(date +"%m,%d") Event-member.data > sendtoday.txt
## The following line is to remove the first to characters of the file
## created above sendtoday.txt and output that to a file called
## send.txt.
## I rewrote this to avoid the useless use of cat.
sed 's/^..//' sendtoday.txt > send.txt
## This is where you use read
while IFS="," read p n l foo bar e; do
sed -e "s/__FULLNAME__:/ $n $l :/g;s/__Project__/ $p /g" Reminder.email > sendnow.txt
cat sendnow.txt
## This is where you need to add the code that sends the emails. Something
## like this:
sendmail $e < sendnow.txt
done < send.txt
exit 0
########
This works like clockwork. Thank you so much for your help. I think this is the most concise answer. I will be seeking your help again in the future :-) .
– S0urc3
Jun 12 '14 at 14:52
add a comment |
up vote
5
down vote
accepted
up vote
5
down vote
accepted
There is no reason to use awk
for this. You could do it directly in the shell using read
. The general format is read foo bar
which will save the first field as $foo
and the rest of each line as $bar
. So, in your case, you would do something like:
while IFS="," read p n l foo bar e; do
sed -e "s/__FULLNAME__:/ $n $l :/g;s/__Project__/ $p /g" Reminder.email;
done < file
The IFS
is the Input Field Separator which, when set to ,
reads comma delimited fields. This lets you take each field and store it in a variable. Note that I used two extra variables foo
and bar
. This is because each field needs its own variable name and you have 6 fields. If you only give 4 variable names, the 4th ($e
) will contain the fields 4 through last.
Now, there are various other syntax errors in your script. First of all the shebang line is wrong, you need #! /bin/sh
, there can't be a blank line between the #!
and the /bin/sh
. Also, in order to assign the output of a command to a variable, you need to use the var=`command`
or, preferably var=$(command)
format. Otherwise, the command itself as a string and not its output is assigned to the variable. Finally, print
is not what you think it is. You are looking for printf
or echo
. So, a better way to write your script would be:
#!/bin/sh
date=$(date "+%m/%d/%y")
echo $date
## The following line is to scan a file called Event-member.data
## and return any lines with todays date and save them to a file
## called sendtoday.txt
grep -n $(date +"%m,%d") Event-member.data > sendtoday.txt
## The following line is to remove the first to characters of the file
## created above sendtoday.txt and output that to a file called
## send.txt.
## I rewrote this to avoid the useless use of cat.
sed 's/^..//' sendtoday.txt > send.txt
## This is where you use read
while IFS="," read p n l foo bar e; do
sed -e "s/__FULLNAME__:/ $n $l :/g;s/__Project__/ $p /g" Reminder.email > sendnow.txt
cat sendnow.txt
## This is where you need to add the code that sends the emails. Something
## like this:
sendmail $e < sendnow.txt
done < send.txt
exit 0
########
There is no reason to use awk
for this. You could do it directly in the shell using read
. The general format is read foo bar
which will save the first field as $foo
and the rest of each line as $bar
. So, in your case, you would do something like:
while IFS="," read p n l foo bar e; do
sed -e "s/__FULLNAME__:/ $n $l :/g;s/__Project__/ $p /g" Reminder.email;
done < file
The IFS
is the Input Field Separator which, when set to ,
reads comma delimited fields. This lets you take each field and store it in a variable. Note that I used two extra variables foo
and bar
. This is because each field needs its own variable name and you have 6 fields. If you only give 4 variable names, the 4th ($e
) will contain the fields 4 through last.
Now, there are various other syntax errors in your script. First of all the shebang line is wrong, you need #! /bin/sh
, there can't be a blank line between the #!
and the /bin/sh
. Also, in order to assign the output of a command to a variable, you need to use the var=`command`
or, preferably var=$(command)
format. Otherwise, the command itself as a string and not its output is assigned to the variable. Finally, print
is not what you think it is. You are looking for printf
or echo
. So, a better way to write your script would be:
#!/bin/sh
date=$(date "+%m/%d/%y")
echo $date
## The following line is to scan a file called Event-member.data
## and return any lines with todays date and save them to a file
## called sendtoday.txt
grep -n $(date +"%m,%d") Event-member.data > sendtoday.txt
## The following line is to remove the first to characters of the file
## created above sendtoday.txt and output that to a file called
## send.txt.
## I rewrote this to avoid the useless use of cat.
sed 's/^..//' sendtoday.txt > send.txt
## This is where you use read
while IFS="," read p n l foo bar e; do
sed -e "s/__FULLNAME__:/ $n $l :/g;s/__Project__/ $p /g" Reminder.email > sendnow.txt
cat sendnow.txt
## This is where you need to add the code that sends the emails. Something
## like this:
sendmail $e < sendnow.txt
done < send.txt
exit 0
########
answered Jun 12 '14 at 8:48
terdon♦
126k31241418
126k31241418
This works like clockwork. Thank you so much for your help. I think this is the most concise answer. I will be seeking your help again in the future :-) .
– S0urc3
Jun 12 '14 at 14:52
add a comment |
This works like clockwork. Thank you so much for your help. I think this is the most concise answer. I will be seeking your help again in the future :-) .
– S0urc3
Jun 12 '14 at 14:52
This works like clockwork. Thank you so much for your help. I think this is the most concise answer. I will be seeking your help again in the future :-) .
– S0urc3
Jun 12 '14 at 14:52
This works like clockwork. Thank you so much for your help. I think this is the most concise answer. I will be seeking your help again in the future :-) .
– S0urc3
Jun 12 '14 at 14:52
add a comment |
up vote
3
down vote
You have used NR==1 condition NR==1print $1
. That means it will consider the first line of send.txt
. Use NR==2 condition to get for 2nd line and so on. OR use loop to go through all the lines like,
while read line
do
p=`echo $line | awk -F '.' 'print $1'`
n=`echo $line | awk -F '.' 'print $2'`
l=`echo $line | awk -F '.' 'print $3'`
e=`echo $line | awk -F '.' 'print $1'`
sed -e "s/__FULLNAME__:/ $n $l :/g;s/__Project__/ $p /g" Reminder.email > sendnow.txt
done<send.txt
This is the approach I wanted to take but couldn't get this to work out. The above IFS approach works good though. Thanks for your input. Ill try to test this again.
– S0urc3
Jun 12 '14 at 14:54
add a comment |
up vote
3
down vote
You have used NR==1 condition NR==1print $1
. That means it will consider the first line of send.txt
. Use NR==2 condition to get for 2nd line and so on. OR use loop to go through all the lines like,
while read line
do
p=`echo $line | awk -F '.' 'print $1'`
n=`echo $line | awk -F '.' 'print $2'`
l=`echo $line | awk -F '.' 'print $3'`
e=`echo $line | awk -F '.' 'print $1'`
sed -e "s/__FULLNAME__:/ $n $l :/g;s/__Project__/ $p /g" Reminder.email > sendnow.txt
done<send.txt
This is the approach I wanted to take but couldn't get this to work out. The above IFS approach works good though. Thanks for your input. Ill try to test this again.
– S0urc3
Jun 12 '14 at 14:54
add a comment |
up vote
3
down vote
up vote
3
down vote
You have used NR==1 condition NR==1print $1
. That means it will consider the first line of send.txt
. Use NR==2 condition to get for 2nd line and so on. OR use loop to go through all the lines like,
while read line
do
p=`echo $line | awk -F '.' 'print $1'`
n=`echo $line | awk -F '.' 'print $2'`
l=`echo $line | awk -F '.' 'print $3'`
e=`echo $line | awk -F '.' 'print $1'`
sed -e "s/__FULLNAME__:/ $n $l :/g;s/__Project__/ $p /g" Reminder.email > sendnow.txt
done<send.txt
You have used NR==1 condition NR==1print $1
. That means it will consider the first line of send.txt
. Use NR==2 condition to get for 2nd line and so on. OR use loop to go through all the lines like,
while read line
do
p=`echo $line | awk -F '.' 'print $1'`
n=`echo $line | awk -F '.' 'print $2'`
l=`echo $line | awk -F '.' 'print $3'`
e=`echo $line | awk -F '.' 'print $1'`
sed -e "s/__FULLNAME__:/ $n $l :/g;s/__Project__/ $p /g" Reminder.email > sendnow.txt
done<send.txt
edited Jun 12 '14 at 16:57
terdon♦
126k31241418
126k31241418
answered Jun 12 '14 at 8:57
Tingrammer
35528
35528
This is the approach I wanted to take but couldn't get this to work out. The above IFS approach works good though. Thanks for your input. Ill try to test this again.
– S0urc3
Jun 12 '14 at 14:54
add a comment |
This is the approach I wanted to take but couldn't get this to work out. The above IFS approach works good though. Thanks for your input. Ill try to test this again.
– S0urc3
Jun 12 '14 at 14:54
This is the approach I wanted to take but couldn't get this to work out. The above IFS approach works good though. Thanks for your input. Ill try to test this again.
– S0urc3
Jun 12 '14 at 14:54
This is the approach I wanted to take but couldn't get this to work out. The above IFS approach works good though. Thanks for your input. Ill try to test this again.
– S0urc3
Jun 12 '14 at 14:54
add a comment |
up vote
1
down vote
maybe wrap your script in something like
for i in $(cat send.txt); do echo "line: $i"; done
?
-1. Very bad idea I'm afraid. 1) That reads the entire line (kind of, see the next point) into$i
which does not help the OP. 2) You never want to dofor i in $(cat file)
, you should always usewhile read i; do ... ; done < file
instead. With the for loop, the line will be split on whitespace so$i
will beProject
, then1,Jack,Chen,06,12,test@cs.fiu.edu
for the first line. 3) This doesn't answer the question in any case since you don't address the actual issue the OP had.
– terdon♦
Jun 12 '14 at 8:51
add a comment |
up vote
1
down vote
maybe wrap your script in something like
for i in $(cat send.txt); do echo "line: $i"; done
?
-1. Very bad idea I'm afraid. 1) That reads the entire line (kind of, see the next point) into$i
which does not help the OP. 2) You never want to dofor i in $(cat file)
, you should always usewhile read i; do ... ; done < file
instead. With the for loop, the line will be split on whitespace so$i
will beProject
, then1,Jack,Chen,06,12,test@cs.fiu.edu
for the first line. 3) This doesn't answer the question in any case since you don't address the actual issue the OP had.
– terdon♦
Jun 12 '14 at 8:51
add a comment |
up vote
1
down vote
up vote
1
down vote
maybe wrap your script in something like
for i in $(cat send.txt); do echo "line: $i"; done
?
maybe wrap your script in something like
for i in $(cat send.txt); do echo "line: $i"; done
?
answered Jun 12 '14 at 8:47
Andreas John
612
612
-1. Very bad idea I'm afraid. 1) That reads the entire line (kind of, see the next point) into$i
which does not help the OP. 2) You never want to dofor i in $(cat file)
, you should always usewhile read i; do ... ; done < file
instead. With the for loop, the line will be split on whitespace so$i
will beProject
, then1,Jack,Chen,06,12,test@cs.fiu.edu
for the first line. 3) This doesn't answer the question in any case since you don't address the actual issue the OP had.
– terdon♦
Jun 12 '14 at 8:51
add a comment |
-1. Very bad idea I'm afraid. 1) That reads the entire line (kind of, see the next point) into$i
which does not help the OP. 2) You never want to dofor i in $(cat file)
, you should always usewhile read i; do ... ; done < file
instead. With the for loop, the line will be split on whitespace so$i
will beProject
, then1,Jack,Chen,06,12,test@cs.fiu.edu
for the first line. 3) This doesn't answer the question in any case since you don't address the actual issue the OP had.
– terdon♦
Jun 12 '14 at 8:51
-1. Very bad idea I'm afraid. 1) That reads the entire line (kind of, see the next point) into
$i
which does not help the OP. 2) You never want to do for i in $(cat file)
, you should always use while read i; do ... ; done < file
instead. With the for loop, the line will be split on whitespace so $i
will be Project
, then 1,Jack,Chen,06,12,test@cs.fiu.edu
for the first line. 3) This doesn't answer the question in any case since you don't address the actual issue the OP had.– terdon♦
Jun 12 '14 at 8:51
-1. Very bad idea I'm afraid. 1) That reads the entire line (kind of, see the next point) into
$i
which does not help the OP. 2) You never want to do for i in $(cat file)
, you should always use while read i; do ... ; done < file
instead. With the for loop, the line will be split on whitespace so $i
will be Project
, then 1,Jack,Chen,06,12,test@cs.fiu.edu
for the first line. 3) This doesn't answer the question in any case since you don't address the actual issue the OP had.– terdon♦
Jun 12 '14 at 8:51
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f136727%2fawk-for-loop-for-each-line-in-a-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
stackoverflow.com/questions/15945302/… this seems to solve your problem.
– Jasper
Jun 12 '14 at 8:27