Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I want to add a " character to the begin of every line in a text file. Is there any simple solution?
sed -i 's/^/"/' file
perl -p -e 's/^/"/' myfile should do it!
perl -p -e 's/^/"/' myfile
$ cat myfile 0 1 2 3 4 5 6 7 8 9 10 $ perl -p -e 's/^/"/' myfile "0 "1 "2 "3 "4 "5 "6 "7 "8 "9 "10
Add a comment
perl -pe '$_ = qq{"$_}' myfile
^
$
Another couple of suggestions:
just in the shell:
tmp=$(mktemp) while read -r line; do printf '"%s\n' "$line"; done < filename > "$tmp" && mv "$tmp" filename
ed:
ed describes.sql.bak <<'END' 1,$s/^/"/ w q END
I would consider one of these ways:
perl -pi.bak -e 's/^/"/' inputfile.txt
Edit file in place, saves a backup in "inputfile.txt.bak".
perl -pe 's/^/"/' inputfile.txt > outputfile.txt
Use shell redirection to print the output to a new file.
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
sed -i 's/^/"/' file