-3

I am a newbie to Linux. Need to replace

/en/family/bitstream/ambiance-bt
/en/family/zxcvbn/bernhard-fashion
/en/family/qwerty/century-751
/en/family/abcd/century-expanded
/en/family/xyz/charter-bt
/en/fonts/sdfsd/dsfsdfs

With

/en/family
/en/family
/en/family
/en/family
/en/family
/en/fonts/sdfsd/dsfsdfs

using sed or some alternative.

ajay
  • 215
  • 1
  • 3
  • 15
  • replacing each one individually. – ajay Jun 28 '18 at 10:09
  • Possible duplicate of [Learning Regular Expressions](https://stackoverflow.com/questions/4736/learning-regular-expressions) – Biffen Jun 28 '18 at 10:10
  • Please avoid *"Give me the codez"* questions that have been asked and answered so many times you have to make an effort to avoid finding an answer. Also see [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/q/261592/608639) – jww Jun 29 '18 at 03:26

3 Answers3

0

Command that given desired result to me is:

sed  's/\/en\/family\/\.*.*/FamilyPage/' filename
ajay
  • 215
  • 1
  • 3
  • 15
-1

Try this command :

sed 's/pattern_to_replace/string_to_insert/' yourfile

I don't give you more precise example because I don't understand what you want to replace.

Edit1, after your first comment :

sed 's@/en/family/.*@FamilyPage@' yourfile
romaric crailox
  • 564
  • 1
  • 3
  • 15
  • pattern_to_replace is changing after /en/family/**** – ajay Jun 28 '18 at 09:58
  • @ajay https://stackoverflow.com/q/4736/418066 – Biffen Jun 28 '18 at 10:03
  • need to remove end part like "/bitstream/ambiance-bt" however above command only replace starting part and rest remains same – ajay Jun 28 '18 at 10:13
  • Above command replace all line startin with /en/family/ and replace it by FamilyPage. You need to keep '.*' to match end of line. According to your example, this command should works sed 's@/en/family.*@/en/family@' yourfile. – romaric crailox Jun 29 '18 at 07:28
-1

If your file content does look like:

/en/family/bitstream/ambiance-bt
/en/family/zxcvbn/bernhard-fashion
/en/family/qwerty/century-751
/en/family/abcd/century-expanded
/en/family/xyz/charter-bt
/en/fonts/sdfsd/dsfsdfs

Use below sed expression to get expected output:

sed  's/\/en\/family\/\*.*/\/en\/family/' yourfilename 

To make changes permanent in yourfilename use below sed expression

sed -i 's/\/en\/family\/*.*/\/en\/family/' yourfilename   
Devendra Singh
  • 146
  • 2
  • 5
  • Why use '\*.\*' within pattern regular expression ? '*' is enough no ? – romaric crailox Jun 28 '18 at 14:55
  • if you use "*" then it will not going to replace entire line from "/en/family" it will give you output /en/familybitstream/ambiance-bt which is not expected according to question. – Devendra Singh Jun 28 '18 at 17:05
  • yes sorry '.*' is necessary. But your command is wrong, you match nothing with it. Try it. It's because of your '\*' before '.*'. Use of '/' to separate field of substitution command is a bad idea when text to replace contain '/' too. This makes command unreadable and causes some mistake such as your error – romaric crailox Jun 29 '18 at 07:27
  • I tried your sed expression but didn't give the desired result. – ajay Jul 02 '18 at 04:22