in a text file (on linux system) I have this string:
O\WIN_INFRASTRUKTUR{Windows Fabrik}\FIM{Forefront Identity Manager(Benutzer)}\EXTRA{}
Now, I want to replace the O\WIN_INFRASTRUKTUR{Windows Fabrik}, but I don't know what is standing in {}. It could be empty or text in it.
I try this, but without success:
sed -e 's/O\\WIN_INFRASTRUKTUR{[a-zA-Z0-9]}/O\\WIFI{}/g'
And that must be the Result:
O\WIFI{}\FIM{Forefront Identity Manager(Benutzer)}\EXTRA{}
Could anyone help me?
use the delimiter as end of your pattern, here it is } so take a class excluding this, any occurrence than your delimiter with [^}]*}
sed -e 's/O\\WIN_INFRASTRUKTUR{[^}]*}/O\\WIFI{}/g' YourFile
sed -e 's/WIN_INFRASTRUKTUR{[^}]*}/WIFI{}/g' <filename>
Thanks, it will be sucessful, but what is, if I want to have this result:
O\WIFI{}\EXTRA{}.
It doesn't matter if I do this:
sed -e 's/O\\WIN_INFRASTRUKTUR{[^}]*}\\FIM{[^}]*}/O\\WIFI{}/g'
than I get only this result: O\WIFI{}
Related
I want to replace below line with next line in all the files. So what sed pattern is used for this. I have tried lot but not figured that out..
checkToken($token['token'])
checkToken($token)
This is what I have tried
sed -i -- 's/checkToken\(\$token\['token'\]\)/checkToken\(\$token\)/g' get_officers_v2.php
You just need to get your escape-characters (\) on the right place like:
sed -ie "s/\(checkToken(\$token\)\['token'\])/\1)/" get_officers_v2.php
I have many web addresses which are including some special interface names, which I would like to remove. Examples:
aaaaaaa-INT1.aaaa.aaaa.com
bbbbbbb-INT2.bbbb.bbbb.com
ccccccc-INT.cccc.cccc.com
So my expected result after sed should be:
aaaaaaa.aaaa.aaaa.com
bbbbbbb.bbbb.bbbb.com
ccccccc.cccc.cccc.com
I have tried this, but it doesnt work:
sed 's/-.*^.//'
Any suggestion please?
To remove the first dash and everything before the first period:
$ sed 's/-[^.]*//' file
aaaaaaa.aaaa.aaaa.com
bbbbbbb.bbbb.bbbb.com
ccccccc.cccc.cccc.com
Solution 1st: Following sed may help you on same too.
sed 's/\([^-]*\)-\([^.]*\)\(.*\)/\1\3/' Input_file
Solution 2nd: With awk.
awk -F"." '{sub(/-.*/,"",$1)} 1' OFS="." Input_file
I have a file that I need to append to certain lines.
I can get the line numbers and have been able to use sed to print the entry but not to append the entry.
All I need to do is something like
sed -n '$VAR s/$/,nosuid/' > to_file
Just can not get the syntax down.
Thank you.
Try doing this :
sed "$VAR s/$/,nosuid/" > to_file
Like Etan Reisner said in the comments, the quotes should be double quotes.
This might work for you:
sed -n $VAR's/$/,nosuid/' > to_file
I want to globally replace the string foo with the string bar, using sed. This should only be done for lines which do NOT start with the string ##Input.
I can't get it to work. I tried things like this but reached a point where I'm not sure if I know what I'm doing:
sed -i '/^##Input/ s/foo/bar/g' myfile
Please help!
You just need to negate the match using !:
sed -i '/^##Input/! s/foo/bar/g' myfile
You got to escape # as in \#.
An ugly answer for an ugly request (i.e. they get what they asked for):
echo \{
for file in *.json; do
sed -n '/^[\{\}]/! s/\([^\,]\)$/\1,/; /^[\{\}]/!p' $file
done
echo \{
I am trying to sed strings in file. This is a file, sed_tmp, with one string:
, "127.0.0.2");
This is the sed command I use:
sed -r 's/[0-9{1,3}]\.[0-9{1,3}]\.[0-9{1,3]\.[0-9{1,3}]/XXX.XXX.XXX.XXX/g' ./sed_tmp
and the result is
, "12XXX.XXX.XXX.XXX");
but I need the result
, "XXX.XXX.XXX.XXX");
What am I doing wrong?
Write the {} outside of []
sed -r 's/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/XXX.XXX.XXX.XXX/g' ./sed_tmp
this works:
sed "s/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/XXX.XXX.XXX.XXX/g"
I've never seen the {1,3} syntax that you are using there, do you have a link to somewhere describing it?
Edit: Seems like sed uses it for slightly differently: http://www.grymoire.com/Unix/Sed.html#uh-35