Lingua Franca Project - Task 16

Hello:

I am trying to complete the

Task 16
The name of our translation service is Lingua Franca , however some of the files mistakenly spell it as Lingua-Franca . Replace the string ‘Lingua-Franca’ with ‘Lingua Franca’ in all occurrences in all the .txt files.

Check your work using this command, confirming that there are 0 occurrences of Lingua-Franca across all text files:

grep -Rl ‘Lingua-Franca’ /.txt | wc -l

Hint

Use the sed command with the -i option. For example, to replace the typo “hellw” with “hello” in a text file called hello_world.txt , you would use the following command:

sed -i ‘s/hellw/hello/g’ hello_world.txt

When I typed the: sed -i ‘s/Lingua-Franca/Lingua Franca/g’ /.txt the terminal show me an error (see the photo)

https://www.codecademy.com/courses/learn-the-command-line/articles/command-line-offline-project

What is the problem with my command line?

3 Likes

I’m assuming you’re on OSX? It’s likely using a different version of sed to the one the project expects (I think the OSX one is BSD based but has diverged from it to some degree too).

There’s a few similar questions linked at the following with some workarounds in the linked posts that other users have found successful:

1 Like

Yes, I am using OSX. Thank you for the explanation. I will try it to see if I can complete that exercise.

2 Likes

I’m also on Mac and I added .bik after the -I (read it somewhere online) and it worked

Final code looked like this:
sed -i.bak ‘s/Lingua-Franca/Lingua Franca/g’ /.txt

1 Like

I also had problems with this. I have a newer Mac and the code that finally worked and gave me an output of 0 after doing the check command was…

sed -i’.original’ -e ‘s/Lingua-Franca/Lingua Franca/g’ /.txt

Another forum took me to this link macos - sed command with -i option failing on Mac, but works on Linux - Stack Overflow and that link gave me the answer.

I had this problem too, but then I used this sed -i “” ‘s/Lingua-Franca/Lingua Franca’ /.txt after finding this website Sed: 'sed: 1: invalid command code R' on Mac OS X · Mark Needham

1 Like
sed -i "" 's/Lingua-Franca/Lingua Franca/' */*.txt

I have referred to some of the posts and comments, this one worked on me and this appeared more simple.

4 Likes

this worked for me too. Simplest solution, thanks!

Hi. Same problem with MacBook Air. Copy and pasted your solution (which I’ve never seen before and would never have known to code this way otherwise). So, how were we supposed to know to add the double quotes (“”) and to take out the g for global after Lingua Franca/??!

This worked! Thanks for sharing :slight_smile:

The reason for this if anyone is confused (as I was and had to look it up)

The code academy course is using ‘GNU Bash’ which is the original Bash platform. Mac OS does not use GNU as its Unix platform, it instead uses FreeBSD. There are subtle differences between the two - annoyingly small differences like this one where the ‘sed’ command behaves differently.

The reason @mars_only 's solution works here sed -i "" 's/Lingua-Franca/Lingua Franca/' */*.txt is because the -i argument in FreeBSD sed needs to have a suffix provided to it. This is so that you can save a new version of the file with a different suffix if you wish. If you do not wish to do this and simply want to overwrite the file you can provide an empty string as the suffix which is what is being done here (-i “”). As for the -g I would leave this in personally as it acts in the same way and will replace the thing globally instead of just doing the first instance it finds in the file (it works here without because the language files all only mentioned ‘Lingua-Franca’ once anyway)

More of the differences between the two types of sed can be found here
I would strongly suggest bookmarking this page in case there’s any other issues like this in the rest of the course.

1 Like

Seems some people had trouble with this one. I made this one work for me.

$ sed -i 's/lingua-franca/Lingua Franca/gi' */*/*

Hi! I’m stuck on the same step but for a different reason. I’m using Bash on Windows so this might be why, I used the code:

$ sed ‘s/Lingua-Franca/Lingua Franca/g’ /.txt

But it have me this error:

sed: can’t read /.txt: No such file or directory

Does anyone know why these wildcards don’t work for me?

Looks like you’re not using any wildcards there?

Unless it just got stripped when you were copying and pasting or writing over or whatever, what you’re doing with /.txt is basically just pointing towards a hidden directory “.txt”. If you want to use the wildcards you need to use asterisks (*), if you use those in your command everything looks like it should work just fine.

Hi. You can use -i.back or just -i ’ '. This would save the command in BSD sed version which is on OS X.