Hi,
I need to add 20 spaces infront of each line. Is there a simple way to avoid typng 20 times space as a replacement pattern.?
Thanks in advance.
Hi,
I need to add 20 spaces infront of each line. Is there a simple way to avoid typng 20 times space as a replacement pattern.?
Thanks in advance.
Don't know if this counts as "simple", but in ksh:
typeset -L20 x=" " ; while IFS="" read l ; do echo "${x}${l}" ; done < data.txt
would work. You're not saving keystrokes, but the number of spaces shifted is instantly obvious.
perl -ne ' print " " x 20 . "$_" ; ' file
awk '{ printf ("%20s%s\n", " ",$0)}' file
in sed, you can just substitute with 20spaces.
sed 's/^/ /' file
there's another syntax for the sed above using {20} but i couldnt get it to work though.
awk '{ printf "%20s%s\n", "", $0 }'
That {20} business is for regular expressions only. You can use a regular expression for the orig text but not the new text in a s command (at least with sed). I like the perl and awk solutions though.
ah, yes. finally it comes back to me. thanks.
I wanted to skip the repeated key strokes in 's/^/ /'. Thank you all for the suggestion. I will switch to awk.