General :: Search & Replace Back Slashes To Forward Slashes In Windows
Feb 11, 2011
Lately I've been needing to delete new untracked files from my versioning system. Being in linux I use: hg status -un|xargs rm And it works nice, but when doing it in windows, hg status lists paths with backslash so that is where stuff goes wrong. So then I try: hg status -un|sed 's/\///g' ...but I get the error: sed: -e expression #1, char 8: unterminated `s' command
Then I try some ascii: `hg status -un|sed 's/o134/o57/g'`...that gets me: sed: -e expression #1, char 14: Trailing backslash And some scripting: hg status -un|sed 's/`echo `/`echo /`/g' ...that gets me: sed: -e expression #1, char 19: unknown option to `s'
I try all the last with any other characters and I get the expected output... so I'm completely lost. I have cygwin, of course, and I want to avoid using a file (that is what I've been doing).
Usually if I have to replace a character in a string I used the sed /s/ command. However, I am having some difficulty in doing the same thing when I have the following string in a variable in my shell script and I need to replace all the forward slashes ("/") to backslashes ("").
I switch between Linux and Windows quite a lot and it's annoying the hell out of me that the Windows command prompt won't auto-complete directory paths when I press Tab if I use forward slashes like in Linux.For example, if I'm trying to navigate to a directory 'bin':
cd /path/to/dir/b <tab> - this won't auto-complete to 'bin' cd path odir <tab> - this will auto-complete.
Can I tell the Command Prompt to use forward slashes instead?
I wrote a hack script that outputs the following every so often: Code: 01/04/11 10:33:02: 97,1413,1447,2860 I must leave the data format the same --but I want a special number from it. In this case it's 97 and it's always going to be the first in the 4 columns of comma delimited items. I can extract with this:
Code: cat datafile | awk -F" " {'print $3'} | awk -F"," {'print $1'} But that's really sloppy. Can someone point out a better way of doing this (with awk) and tell me why?
And I'm trying to count the number of slashes in each line. I figured (with my limited knowledge of bash) that the best thing to use would be sed. So I ran this to print "not /": sed '!s////g' file # and eventually adding " | wc -m" to it. and I got the same result as if I ran cat, no modification at all:
I have a back-end server behind a proxy machine. I would like non-SSL requests to the proxy to be rewritten into HTTPS requests to the back-end server, while not screwing up URLs with missing or misplaced trailing URL slashes. So far, on the proxy side, I have this in a virtual host for port 80:
But adding anything else to the URL fails, as the back-end server name gets stuck into the proxied [URL]... The rewrite log seems okay, I think. So I guess this is failing at the reverse proxy rule? Where am I going wrong?
I prefer to delete trailing slahes from pathes. Until now I used sed:
Code: $ myPath=/home/ladygaga/// $ echo "$myPath" | sed 's//*$//' /home/ladygaga I played around to accomplish the same with on-board means of bash without using sed, but for example this line only deletes one trailing slash: Code: $ myPath=/home/ladygaga/// $ echo ${myPath%/*} /home/ladygaga// Is there a way to delete trailing slahes with just on-board means of bash?
In the above code ^<YAHOO> search is not working (I want lines "except YAHOO"). I know that [^ab] will work for "except a,b" characters. How can I say "except word" in regular expressions?
Hello, I need some help searching through multiple files, finding a line and replacing that line. The line I am searching for is:
password key ******* 1222554
ultimately I want to be able to delete the numbers after the asterisks . my thoughts are to create a script that will search for the line password key ******* and delete it then replace it with password key ******* my files are located in /opt and they are all txt files.
I'm fairly comfortable with emacs but I can't seem to find how to do this. I deal with a lot of text files and find myself performing a lot of regular expression replacements to correct the formatting of the text -- or to extract certain tidbits of data from large ugly-looking files.
I know how to perform a regular expression replacement in one buffer at a time. But how do you perform a regular expression search and replace across all open buffers? I have found a method to perform a regex search and replace across a directory by marking files but I need to do it in the open buffers.
I've got a list of files that I've copied from my terminal and pasted into gedit and into OO.o writer. Since the files are all created by gedit, in each case there is both file and file~. I want to get rid of all the 'file~' lines. I thought I could do search and replace using *~, but this doesn't work.
But the problem is that in this case i just wanted to append "/home/dest" for which I could easily escape "/" with just two "", but I wonder if i have a long path like "/a/b/c/d/e/f/g/h/i/j" I will have to escape so many /. Is there any other way by which I can avoid escaping forward slash.
I tried following:
But receiving follo error
Bareword found where operator expected at -e line 1, near "s/destination-path=/'destination-path=/home" syntax error at -e line 1, near "s/destination-path=/'destination-path=/home" Bad name after dest' at -e line 1. tried with enclosing in double quotes as well but in vain
How can I move around the bash commandline efficiently?In the Windows prompt, one can go back or forward one word by pressing ctrl and <-/->.What's the equivalent in a bash environment?
Is it possible to use cd command to navigate back and forward (like browser)?. Something similar to cd - but it only swaps current and last location. I know I can push dir on stack, it would be great to use cd -> and cd <-, though.
I'm trying to use sed to search and replace backwards. The problem is that I have a shell script that is required to put commas into big numbers. For example
9999999 as 9,999,999
I've tried a few things, but none seem to work:
Code:
$ echo 9999999 | sed -e 's/([0-9]{3})/,1/g' ,999,9999 $ echo 9999999 | sed -e 's/([0-9]{3})$/1,/g' -e 's/([0-9]{3})/1,/g' 999,999,9, $ echo 9999999 | sed -e 's/([0-9]{3})$/1,/g' -e 's/([0-9]{3})/,1/g'
[ode]....
It would be much easier if I could search backwards! For example Bash parameter substitution style:
i need to change a binary file, let's say to find and replace username:
find string: "/home/name/bla-bla-bla/ " new string: "/home/anewname/bla-bla-bla/ "
i can do it, for example, in emacs (hexl-mode), but interesting in writing a script instead. it will be much more better for me if i could do it automatically. is there an analog of: sed 's/string1/string2/g' ? P.S. the best way is to recompile the binary files i have, but there are no sources available.
Back to the problem: I wrote a little bash script that people around here can run to search and replace strings in the current directory and all subdirectories. However, whenever there is a space in the new string (the one doing the replacing), I get this error:
I need a command to search a string in a file and then to convert the next string in the same line from hexadecimal to binary. I was able to put everything in capitals. The original file can be as such:
E 2 C 1 794 T ffff E 2 C 1 787
It is not always FFFF! I am trying to do this in a file at once, not reading line by line (using while).
I want to do search and replace in multiple files. I've seen that it possible to create a sed script but I haven't got the talent to do it myselfWhatd is to locate all instances of a word - lets say 'day' - and replace it with for example 'night' in all odm-documents in a specific folder. It would be great if the search only matched whole words and was case sensitive.
I'm wanting to mod some PHP files across a hierarchy and thought I'd drive it with find + grep + xargs
I built up a command line which I was confident would do the job, but now can't save the results.
First I tried this:
Code: find . -name *.php | xargs grep serialize | cut -d: -f1| sort -u | xargs sed -i s/serialize/serialise/g but that didn't work: Code: sed: illegal option -- i so I thought I'd try using Code:
I installed Ubuntu 10.04 on my systems. In the file browser or any internet browser, if I click on back, forward or up, nothing happens. I stays on the current page/location. Even if goes back, sometimes, it again comes back automatically to current page/location. I can navigate using keyboard but not with mouse.
why these buttons would not work in opera but work in nautilus and firefox? I've tried to change the mouse settings in opera and nothing works. thoughts?
I'm running Sabayon Linux, and recently when through a major upgrade where a lot of packages were upgraded.
After the upgrade, when launching firefox, the back and forward icons are missing. The buttons are actually there, as I can still select an empty grey rectangle. I also checked and it's happening for all users on the system.
I was using the persona's theme, but I stopped using that (for performance reasons). I just disabled it, I haven't actually removed it.
I tried re-installing gnome-icon-theme package from a suggestion on another linuxquestions.org thread, but that didn't help.
It's not a big deal as I can still use the buttons, but curious if anyone has any insight into what I can do to get the icons back.