XXXX is in every lines of file1.txt and i want to replace them with each line in file2.txt:
home
school
cinema
so output file is:
Monday home
Tuesday home
home Wednesday
Thursday home
Monday school
Tuesday school
school Wednesday
Thursday school
Monday cinema
Tuesday cinema
cinema Wednesday
Thursday cinema
I got the file2.txt has many lines so i can't do it by hand. So, i need a solution for it.
Thanks for your time.
cat file2 | xargs -L1 -I{} sed -e 's/XXXX/{}/g' file1
Monday home
Tuesday home
home Wednesday
Thursday home
Monday school
Tuesday school
school Wednesday
Thursday school
Monday cinema
Tuesday cinema
cinema Wednesday
Thursday cinema
content is fine. Think it's just not work for me. Could u explain why i get this on first solution? SOrry if i bother you because i really need this whereas i'm noob myself
#!/bin/bash
set -x
sed 's/XXXX/'$LINE'/' file1.txt >>file3.txt
+ sed s/XXXX// file1.txt
done file2.txt
-bash: syntax error near unexpected token `done'
#!/bin/bash
set -x
while read LINE
do
sed 's/XXXX/'$LINE'/' file1.txt >>file3.txt
done<file2.txt
cat file3.txt
here is exact file3.txt:
Monday home
Tuesday home
home
Wednesday
Thursday home
Monday school
Tuesday school
school
Wednesday
Thursday school
I don't know where's the 'cinema' and why it's break down after each replacements.
+ read LINE
+ sed $'s/XXXX/home\r/' file1.txt
+ read LINE
+ sed $'s/XXXX/school\r/' file1.txt
+ read LINE
+ sed $'s/XXXX/cinema\r/' file1.txt
+ read LINE
I could see a \r carriage return character from the data you have posted. Was file2.txt transferred from a windows environment to unix?
If yes, please remove the CRLF (carriage return line feed) characters using command dos2ux or dos2unix . Not sure which one is available in your system.