I have a txt file that contains a couple thousand dates. I would like to add a string to every line using osx bash. It works just fine in subline using regex but I can't get it to do what I want in bash - even using the same regex.
I figured SED is the right tool, added -E to get proper regex, then set 'select' every line and add 'whatever' to the end of it. However - sed is replacing the first letter of the line instead of appending it to each line. Any clue why that might be?
sed -E 's/^(.*)$/\1whatever/g' testbase.txt
Thanks in advance for any hint - I'm looking forward to my 'aha' moment.
mi
add: I did all my testing on a file that contains an email list (figuring text is text) instead of the file with the dates. Using the following command kindly provided by a commenter (thanks a lot!), I get the correct results (date, then whatever) in the date/time file. However - in the email list, I get a list of emails and between every line it adds another line with 'whatever'.
sed 's/^\(.*\)$/\1whatever/g' testbase1.txt
Here's the output of od -c datetimefile
$ od -c datetimefile.txt 0000000 a b r c o o k i e 3 @ g m a i l 0000020 . c o m \r \n d i c o o k i e 3 @ 0000040 a o l . c o m \r \n p o r c o o k 0000060 i e 7 6 @ g m a i l . c o m \r \n 0000100 t e r c o o k i e 4 @ g m a i l 0000120 . c o m \r \n s u m c o o k i e l 0000140 1 1 @ g m a i l . c o m \r \n n l 0000160 c o o k i e 0 @ g m a i l . c o 0000200 m \r \n m c d c o o k i e 2 @ h o 0000220 t m a i l . c o m \r \n a n d r c 0000240 o o k i e a 1 1 @ g m a i l . c 0000260 o m \r \n c a c o o k i e @ e l l 0000300 e r v i k . d k \r \n n a v e c o 0000320 o k i e r d 1 @ g m a i l . c o 0000340 m \r \n f a r i a c o o k i e 1 0 0000360 @ g m a i l . c o m \r \n y o c o 0000400 o k i e o e 4 0 1 @ y a h o o . 0000420 c o m \r \n a n d c o o k i e r e 0000440 n 2 3 @ g m a i l . c o m \r \n c 0000460 o o k i e k a 7 7 @ h o t m a i 0000500 l . c o m \r \n l i l c o o k i e 0000520 8 8 @ a o l . c o m 0000532
output of od -c emaillistfile
$ od -c testbase1.txt 0000000 2 0 2 0 - 1 2 - 2 4 2 1 : 3 2 : 0000020 4 4 \n 2 0 2 0 - 1 2 - 2 4 2 1 : 0000040 3 2 : 4 4 \n 2 0 2 0 - 1 2 - 2 4 0000060 2 1 : 3 2 : 4 4 \n 2 0 2 0 - 1 2 0000100 - 2 4 2 1 : 3 2 : 4 4 \n 2 0 2 0 0000120 - 1 2 - 2 4 2 1 : 3 2 : 4 4 \n 2 0000140 0 2 0 - 1 2 - 2 4 2 1 : 3 2 : 4 0000160 4 \n 2 0 2 0 - 1 2 - 2 4 2 1 : 3 0000200 2 : 4 4 \n 2 0 2 0 - 1 2 - 2 4 2 0000220 3 : 2 6 : 0 1 \n 2 0 2 0 - 1 2 - 0000240 2 4 2 3 : 2 6 : 0 1 \n 2 0 2 0 - 0000260 1 2 - 2 4 2 3 : 2 6 : 0 1 \n 2 0 0000300 2 0 - 1 2 - 2 4 2 3 : 2 6 : 0 1 0000320 \n 2 0 2 0 - 1 2 - 2 1 0 1 : 4 9 0000340 : 3 4 \n 2 0 2 0 - 1 2 - 0 8 0 1 0000360 : 3 9 : 0 6 \n 2 0 2 0 - 1 2 - 1 0000400 0 1 1 : 4 7 : 4 3 \n 2 0 2 0 - 1 0000420 2 - 1 5 1 5 : 3 0 : 3 2 \n 2 0 2 0000440 0 - 1 2 - 1 5 1 6 : 0 2 : 5 6 \n 0000460 2 0 2 0 - 1 2 - 1 9 1 6 : 3 5 : 0000500 4 8 \n 2 0 2 0 - 1 2 - 1 9 2 1 : 0000520 5 8 : 1 1 \n 2 0 2 0 - 1 2 - 2 0 0000540 1 5 : 4 0 : 5 2 0000550
\r
. I'm trying to find a duplicate target. Meanwhile you can solve your problem by runningdos2unix
(or see https://stackoverflow.com/q/800030) on the files before applying Sed to remove the carriage returns. – Quasímodo Nov 29 '20 at 00:26sed "s/$/whatever/"
is pretty much enough to append AFAIK. – D4RIO Nov 29 '20 at 04:32dos2unix filename
– thanasisp Nov 29 '20 at 12:51