Languages and Scripting

Re: ksh help: to remove all occurrences of "/string" from every line in the file

 
Hanry Zhou
Super Advisor

ksh help: to remove all occurance of "/string" from every line in the file

There are multiple lines in a file, and all look like the following:
f1:string1/string2 f2:string3/string4

f3:string5/string6 f4:string7/string8

....

 

I wanted to all characters with such format of "/stringx", in cluding / in the file. Would you please help me out?

 

Thank you!

 

none
6 REPLIES 6
Dennis Handly
Acclaimed Contributor

Re: ksh help: to remove all occurrences of "/string" from every line in the file

You could use sed:

sed -e 's:/string.::g' file > file.new

 

I'm removing that arbitrary "x" char too.

Hanry Zhou
Super Advisor

Re: ksh help: to remove all occurrences of "/string" from every line in the file

I did not make myself clear.

 

/stringx, string could be any combination of of any characters or digits, it is not all the same. so, for instance,

/string1 could be "/asdbas_agd_sadf9", /string2 could be "/juhsdf_asb8bsd"

none
Steven Schweda
Honored Contributor

Re: ksh help: to remove all occurrences of "/string" from every line in the file

 
Dennis Handly
Acclaimed Contributor

Re: ksh help: to remove all occurrences of "/string" from every line in the file

>string could be any combination of of any characters or digits

 

So you want to remove any combination after "/" to a space or newline?

Hanry Zhou
Super Advisor

Re: ksh help: to remove all occurrences of "/string" from every line in the file

I wanted to remove, not replace, for instance:

 

f1:anycharactersordigits/anycharactersdigits f2:anycharactersordigits/anycharactersordigits

f3:anycharactersordigits/anycharactersdigits f4:anycharactersordigits/anycharactersordigits

....

 

so, i wanted to remove "/anycharactersdigits" from every line, including "/".

 

so, they will become the following:

f1:anycharactersordigis f2:anycharactersordigits

f3:anycharactersordigis f4:anycharactersordigits

 

any characters contain letters digits, "-", or "_", no space.

 f1, f2, f3.. contains any characters, digits, "-", or "_" as well, no space.

 

thank you!

none
Steven Schweda
Honored Contributor

Re: ksh help: to remove all occurrences of "/string" from every line in the file