append multiple lines in a file in Linux
Need below three lines added to the end of file
commit;
disconnect;
exit;
There are many ways to do that the same
1) By echo command
echo "commit;">>abc.sql
echo "disconnect;">>abc.sql
echo "exit;">>abc.sql
2) By printf command
printf '%s\n%s\n%s''commit;' 'disconnect;' 'exit;'>>abc.sql
where %s is for string and \n is for new line
3) By cat command
cat<
commit;
disconnect;
exit;
EOF
Where EOF is lebel (You can use any word)
4) By cat command
echo -e "commit; \n disconnect; \n exit;">abc.sql
if you have a file named test.txt with following contents:
ReplyDeletecommit;
disconnect;
exit;
its easy to write a small shell script. This will also work when we have large files of 100s of records.
$ for i in `cat text.txt`
do
echo $i >> test_in_oneline.out
done