New answers tagged

1

One way to do it is to use the end match marker: %s/\n\ze\D/\t/ Another way to do it is to using negative lookahead: %s/\n\d\@!/\t/ They are not exactly equivalent, the second will also replace the last newline in a file.


3

You're almost there, but your regular expression is replacing both the newline and the non-digit with a tab. How about replacing every newline followed by a non-digit with a tab and that same non-digit? %s/\n\(\D\)/\t\1/g The escaping is a bit messy, but basically you have a grouping around the \D that will capture whatever the non-digit is. This is then ...


-2

I hope this will help you :%s#\n.\D#\t#g


3

Since you're not actually changing the "cast" line: sed '/cast \$recv \$UE_CAPABILITY_ENQUIRY/{a\ set trans_id 1 n;d}' file As Kusalananda comments, this command: when one of the wanted "cast" lines is found: append the new line take the next line from the file (the unwanted "set" line) and delete it In hindsight, this does not ...


1

You need to escape the \ with another \. You can do this in a bash shell variable as follows sed -i -e "s/${old//\\/\\\\}/${new//\\/\\\\}/g" filename See man bash Parameter Expansion for ${parameter/pattern/string}. We use the version with // instead of / to do it repeatedly. And we need to escape \ with itself, so it gets duplicated a lot.


0

You can try this plugin. https://github.com/tpope/vim-abolish This plugin can help you to match not just the case sensitive text, also its variants too. Like /good{,ies} will match both good as well as goodies. Similarly, it can replace with case sensitive as well as variant included. :%S/long/short/g will replace long with short, Long with Short,...


2

generate a sed script from your index file (File2) instead of a loop then run that script against your File1.. It will be MUCH faster :). awk '{ print "s/sp_"$1"/"$2"/g"}' File2.txt > tranform.sed then do: sed -i -f transform.sed File1.txt so your entire script could be: awk '{ print "s/sp_"$1"/"$2"/g"}' File2.txt > transform.sed sed -f ...



Top 50 recent answers are included