If trial.sql is a straight text file containing the lines as you report above, the cat command will be a better tool to use than grep because grep is intended to search files for specific strings while cat will print the contents of a file to standard output (the terminal screen). In a terminal window, run man grep and man cat to get more information on these commands.I suggest you use a for loop to process each line. The format of a for loop is:
for variable-name in list
do commands
done
or
for variable-name in list;do commands; done (all on a single line)
The for loop puts one item from list in variable-name with each iteration, so if the list you provide is the output of the cat command when run on ~/trial.sql, you can append @abc.net with the echo command then redirect the output to a temporary file, rename (or delete) the original file, then rename the temporary file as the original file like this:
--------------
#!/bin/bash
#trial.sh
# Use cat to output the contents of trial.sql
# to stdout.
# Run a for loop to append abc.net to each
# line of output from cat and save the result
# in a temporary file.
for a in $(cat ~/trial.sql)
do echo $a@abc.net >> ~/trial.temp
done
# Rename trial.sql as trial.sql.old.
mv ~/trial.sql ~/trial.sql.old
# Finally, rename trial.temp as trial.sql
mv ~/trial.temp ~/trial.sql
# end
end-------------
This is a quick and dirty script, and I am sure there are more elegant ways to get the job done (I tried to make as much as clear as I could), but I wanted to make this as educational as possible.
The tilde (~) in the path names (~/trial.sql) is shorthand for /home/$USER (the current user's home directory).
The for loop takes the output of $(cat ~/trial.sql) and puts one line at a time in the variable a ($a) then runs the command echo $a@abc.net >> ~/trial.temp which does the following:
outputs the contents of the variable ($a) and the text @abc.net (no spaces) to standard output (the terminal screen).
redirects (>>) the output of the echo command and appends it to the end of the file ~/trial.temp
This process is repeated for each iteration (line) of the for loop.
mv ~/trial.sql ~/trial.sql.old renames the original file ~/trial.sql as ~/trial.sql.old so the original information is preserved.
If you do not want to preserve the original information, you can replace this line with:
rm -f ~/trial.sql
The -f option to the rm command forces deletion of the target with no user interaction.
mv ~/trial.temp ~/trial.sql renames the temporary file as the original file (~/trial.sql).
If this is not what you wanted, or if the contents of the trial.sql file is not exactly as you posted, this may not work as expected.
As a test, open a terminal window, and run the command cat ~/trial.sql (or use the full path to the file if it is not in your user's home directory) to make sure the output is as described in your original post.
HTH,
Ernie Registered Linux User 247790
ICQ 41060744