Re: Assitance with perl

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On 02/02/2022 11:34 PM, Jon LaBadie wrote:
> On Wed, Feb 02, 2022 at 08:54:38PM -0500, H wrote:
>>>>> I am writing a long bash script under CentOS 7 where perl is used for manipulating some external files. So far I am using perl one-liners to do so but ran into a problem when I need to append text to an external file.
>>>>>
>>>>> Here is a simplified example in the bash script where txt is a bash variable which I built containing a longish text with multiple newlines:
>>>>>
>>>>> txt="a b$'\n'cd ef$'\n'g h$'\n'ij kl"
>>>>>
>>>>> A simplified perl one-liner to append the text in the variable above to some file in the bash script would be:
>>>>>
>>>>> perl -pe 'eof && do{print $_'"${txt}"'; exit}' someexternalfile.txt
>>>>>
>>>>> This works when fine when $txt does /not/ contain any spaces but falls apart when it does.
>
> In a shell script why not stick to shell tools?
>
>   printf "%s" "${txt}" >> someexternalfile.txt
>
I want to use similar patterns of perl one-liners for more complicated text substitutions. If I cannot get the simple example above to work, I surely cannot get more complicated text substitutions, including substitutions spanning multiple lines, to work.

_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
https://lists.centos.org/mailman/listinfo/centos




[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]


  Powered by Linux