Surround lines with quotes
Recently, I have been transferring a huge file (more than 7k lines) to
Mozilla/5.0 (Amiga; U; AmigaOS 1.3; en; rv:220.127.116.11) Gecko/20081204 SeaMonkey/1.1.14
What I needed was:
AGENTS = [
Modifying this manually is overkill, isn’t it? Honestly, last time I ended with copying only a few first lines and do boring manual work, but this time I decided to add functionality that allows to chose random User-Agent from the whole list.
My first thought was to use Vim macro, see here: http://vim.wikia.com/wiki/Macros
Thankfully, I found a faster and easier solution for how to wrap quickly my data.
sed command in Linux: https://www.geeksforgeeks.org/sed-command-in-unix/
So what I did is:
First, I copied all lines of
User-Agents to empty Ruby file.
sed -e "s/\(.*\)/'\1'/" agents.rb > temp_quotes.rb
sed -e "s/\(.*\)/\1,/" temp_quotes.rb > temp_comma.rb
mv temp_comma user_agents.rb