Reputation: 853
i have a text file "names.txt" that contains a list of words like so :
Adidas
Android
Bluetooth
Minaret
Mushroom
acorn
airplane
amazon
i want this file to be exactly like :
"Adidas" = "";
"Android" = "";
"Bluetooth" = "";
"Minaret" = "";
"Mushroom" = "";
"acorn" = "";
"airplane" = "";
"amazon" = "";
Any idea how to accomplish this ? Thank you
Upvotes: 0
Views: 4993
Reputation:
Awk way
awk '$0="\""$0"\" = \"\";"' file
Sed way
sed 's/.*/"&" = "";/' file
Upvotes: 0
Reputation: 263547
Use this sed
command:
sed 's/.*/"&" = "";/'
To modify the file in place, you can do this:
sed 's/.*/"&" = "";/' filename > tmp && mv tmp filename
(pick a temporary file name that doesn't already exist; I often use $$
, the current shell's process ID) or:
sed -i.bak 's/.*/"&" = "";/' filename
The latter copies the original file to filename.bak
.
Upvotes: 2
Reputation: 290155
What about this sed?
$ sed -e 's/^/"/' -e 's/$/" = "";/' file
"Adidas" = "";
"Android" = "";
"Bluetooth" = "";
"Minaret" = "";
"Mushroom" = "";
"acorn" = "";
"airplane" = "";
"amazon" = "";
It replaces the beginning of the line (^
) with "
and the end of line ($
) with " = "";
. So it eventually adds "
at the beginning and " = "";
at the end.
Use sed -i.bak '...'
to in place edit.
You can also use bash for this:
while read line
do
printf "%s%s%s\n" '"' $line '" = "";'
done < file
Or awk:
awk '{printf "%s%s%s\n", "\"", $0, "\" = \"\";"}' file
Upvotes: 3