|
|
Subject:
Removing two types of trailing characters from output line.
Category: Computers > Algorithms Asked by: lcid-ga List Price: $10.00 |
Posted:
17 Oct 2006 18:09 PDT
Expires: 16 Nov 2006 17:09 PST Question ID: 774516 |
I need to remove a trailing backslash=dot "\." and a trailing backslash-dot-dot "\.." from output created by LogParser 2.2. It's a listing of directories. For some reason, the output of a single directory can be shown as follows: c:\alldata\ c:\alldata\. c:\alldata\.. I just need the first occurence. | |
| |
| |
|
|
There is no answer at this time. |
|
Subject:
Re: Removing two types of trailing characters from output line.
From: gowthamavenkatesh-ga on 17 Oct 2006 20:55 PDT |
try the following using simple c++ ---------------------------------- char *str = "c:\\alldata\\xyz\\.."; char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT]; _splitpath( str, drive, dir, fname, ext ); in drive & dir u can get path.. |
Subject:
Re: Removing two types of trailing characters from output line.
From: dmrmv-ga on 18 Oct 2006 09:53 PDT |
1. Install the Free Software Foundation GNU coreutilities: http://gnuwin32.sourceforge.net/packages/coreutils.htm 2. Set your path environment variable to point to the utilities. 3. grep -v "\\\." output.txt > new.txt Assuming your input from above is in output.txt: c:\alldata <<I want to keep this row c:\alldata\. <<I want to delete this row c:\alldata\.. << I want to delete this row c:\cygwin\ << Keep c:\cygwin\. << Delete c:\cygwin\.. << Delete c:\windows <<keep c:\temp <<keep c:\temp\. <<delete c:\temp\.. <<delete new.txt will now contain: c:\alldata <<I want to keep this row c:\cygwin\ << Keep c:\windows <<keep c:\temp <<keep There are numerous other ways you could do this with awk or sed as well. Note that the reason you are seeing this is that the directory output is adding the shortcuts "." and ".." which are the current and parent directories respectively. EG try typing "dir ." and "dir .." to see what you get. Note I'm not a researcher so this won't cost you anything if it works. |
Subject:
Re: Removing two types of trailing characters from output line.
From: lcid-ga on 18 Oct 2006 15:39 PDT |
Sometimes within a row is an embedded "\.". I think these are hidden directories Hypothetical example c:\alldata\nextdir\.anotherdir <<-"Real" Directory c:\alldata\nextdir\.anotherdir\. <<-Current Directory with the single dot c:\alldata\nextdir\.anotherdir\.. <<-Parent directory with double dot. I would like to keep the first instance, not the second and third. A simple GREP finds the second and third instance too. I suppose I could just read the book called "Mastering Regular Expressions" and figure this out. |
Subject:
Re: Removing two types of trailing characters from output line.
From: dmrmv-ga on 19 Oct 2006 09:42 PDT |
You can tell grep to only match at the end of a line using the "$" character: grep -v "\\\.\.$" output.txt | grep -v "\\\.$" > new.txt Note this won't work with the sample where you have added comments since it is no longer at the end of the line. You could do this with a single grep to match one or more "." chars at the end but I'm not skilled enough at regex to figure out how. The sample above takes output.txt containing: c:\alldata\nextdir\.anotherdir c:\alldata\nextdir\.anotherdir\. c:\alldata\nextdir\.anotherdir\.. and the result in new.txt is: c:\alldata\nextdir\.anotherdir |
Subject:
Re: Removing two types of trailing characters from output line.
From: dmrmv-ga on 20 Oct 2006 07:51 PDT |
Following up on my previous comment, you can probably do a single grep searching for a "." at the end of a line, as I don't think Windows will allow a filename to end with a period: grep -v "\.$" output.txt > new.txt |
Subject:
Re: Removing two types of trailing characters from output line.
From: diaphragm-ga on 14 Nov 2006 13:05 PST |
if you already got perl installed in your server then no need to install any other thirdparty programs to do this... simply go to the directory where you've got your logs stored. then type this: perl -pi~ -e "s/\\(\.|\.\.)$//" [FILENAME] (this presumes perl is already in your environment variables.) for example you might have a file called "log.txt" go to dir where log.txt is saved (eg c:\logs) then type: perl -pi~ -e "s/\\(\.|\.\.)$//" log.txt perl will create a log.txt~ as a backup of original file and then remove the dots according the regexp i wrote there in your original file (log.txt) so at the end you'll have a log.txt (the edited file) and a log.txt~ backup of the edited file! infact i just used this command this evening for renaming some text in 10,000 files ;) |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |