I want to put each line within quotation marks, such as:
abcdefg hijklmn opqrst
convert to:
"abcdefg" "hijklmn" "opqrst"
How to do this in Bash shell script?
$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script. Follow this answer to receive notifications.
So as far as I can tell, %% doesn't have any special meaning in a bash function name. It would be just like using XX instead. This is despite the definition of a name in the manpage: name A word consisting only of alphanumeric characters and under- scores, and beginning with an alphabetic character or an under- score.
Optional Rule # 4. Even if a paragraph lists quotes from more than one source, you can still summarize them into one reference placed after the last quote or at the end of the paragraph. In this case, separate the different authors listed in your reference by a semicolon, in both MLA and Chicago.
Using awk
awk '{ print "\""$0"\""}' inputfile
Using pure bash
while read FOO; do echo -e "\"$FOO\"" done < inputfile
where inputfile
would be a file containing the lines without quotes.
If your file has empty lines, awk is definitely the way to go:
awk 'NF { print "\""$0"\""}' inputfile
NF
tells awk
to only execute the print command when the Number of Fields is more than zero (line is not empty).
I use the following command:
xargs -I{lin} echo \"{lin}\" < your_filename
The xargs
take standard input (redirected from your file) and pass one line a time to {lin}
placeholder, and then execute the command at next, in this case a echo
with escaped double quotes.
You can use the -i
option of xargs to omit the name of the placeholder, like this:
xargs -i echo \"{}\" < your_filename
In both cases, your IFS must be at default value or with '\n'
at least.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With