I have a file that looks like this.
/n01/mysqlarch1/mysql-bin.000011
/n01/mysqlarch1/mysql-bin.000012
/n01/mysqlarch1/mysql-bin.000013
/n01/mysqlarch2/mysql-bin.000014
/n01/mysqlarch2/mysql-bin.000015
/n01/mysqlarch2/mysql-bin.000016
I want to be able to search for both mysqlarch1 and mysqlarch2 and replace with mysqldata1.
Therefore the file would end up looking like...
/n01/mysqldata1/mysql-bin.000011
/n01/mysqldata1/mysql-bin.000012
/n01/mysqldata1/mysql-bin.000013
/n01/mysqldata1/mysql-bin.000014
/n01/mysqldata1/mysql-bin.000015
/n01/mysqldata1/mysql-bin.000016
any help would be greatly appreciated.
sed can do the job:
sed 's/mysqlarch[12]/mysqldata1/g' file
/n01/mysqldata1/mysql-bin.000011
/n01/mysqldata1/mysql-bin.000012
/n01/mysqldata1/mysql-bin.000013
/n01/mysqldata1/mysql-bin.000014
/n01/mysqldata1/mysql-bin.000015
/n01/mysqldata1/mysql-bin.000016
Related
I'm new here and already tried to find solution to the following requirement without success. I'm trying to achieve this:
I have these 5 folders:
ServiceEngine
PaymentEngine
InvoiceEngine
ProcessEngine
OrderProcessEngine
Inside each of these folders, I have a log file with default path location to store the log files e.g. ServiceEngine/logs
The log file contain the following path structure:
name="RollingRandomAccessFile" fileName="logs/engine.log"
filePattern="logs/engine-%i.log"
I expect to find a way that I retrieve the name of the current folder which I'm in and replace the string engine with folder name
Example: I'm in ServiceEngine folder and execute a command that retrieve the current folder name. The expected result is:
name="RollingRandomAccessFile" fileName="logs/ServiceEngine.log"
filePattern="logs/ServiceEngine-%i.log
Later I change the directory to PaymentEngine and the expected result is:
name="RollingRandomAccessFile" fileName="logs/PaymentEngine.log"
filePattern="logs/PaymentEngine-%i.log
and so on. Maybe there is a smarter way to create a script that update the string in a loop like do; if ... fi; done or to use the for in ... loop.
Do you mean something like this?
~/ServiceEngine$ cat logfile
name="RollingRandomAccessFile" fileName="logs/engine.log"
filePattern="logs/engine-%i.log"
~/ServiceEngine$ awk -v path=$(basename $(pwd)) 'gsub("engine", path)' logfile
name="RollingRandomAccessFile" fileName="logs/ServiceEngine.log"
filePattern="logs/ServiceEngine-%i.log"
See basename, declaring variables in awk and awk gsub.
I guess I don't understand your question, but:
dir=$( basename $( pwd ) )
echo name="RollingRandomAccessFile" \
fileName="logs/$dir.log" \
filePattern="logs/$dir-%i.log"
Is that what you're looking for?
It sounds like you are looking for something like this:
$ sed 's/\bengine\b/'$(basename $(pwd))'/' logs
When run from within one of your folders, it spits out the text you're asking for. It wasn't clear what you wanted to do with that text though.
So I have a bunch of files named like this:
Movie Name Here [720p].mp4
And I want to rename them like this:
Movie Name.mp4
I have tried stuff like:
mv ./*\ [720p].mp4 ./*.mp4
But it doesn't work, for whatever reason. Any ideas on the quickest way to do this?
Use this code to remove all ' [720p]':
rename 's/ \[720p\]//g' ./*
I'm trying to find a file in which the directory will change its name with upcoming versions, so an example could be that it is located under /opt/here/test-1.44/bin/progname and will follow the format same time.
I'm looking to do something like if File.exist?("/opt/here/test-*/bin/progname") but is that the correct format? When searching around I'm also seeing references to using Dir, so would it be something like if Dir['/opt/here/*'.select { |f| f =~ /progname/} then ?
Thanks!
Do
Dir.glob("/opt/here/test-*/bin/progname").empty?
Use any? instead of empty? if you want true when there is such file.
Suppose i have a folder structure which has a path like this..
C:\Fold1\Fold2\Fold3\Sample.xls
I want to display the File name i.e Sample.xls in a separate text file along with the Last folder name. That is Fold3
Output in Text file should be like this..
Fold 3
Sample.xls
Please need the code ASAP...
I would do a pure Dir /B in a temp file and then use some awk or grep solution to extract the part I need with regular expressions.
There are many free tools to allow this (GNU for Windows).
I'm wondering what's the best way to combine multiple .html files (spread across many folders) into one single html file. If someone could create a simple bash command that would be fantastic. (This is a workaround so I can use firebug's command line API to effectively search an entire site for html selector combinations. As far as I know, firebug can only search on one page.)
Any help is greatly appreciated for this stymied front-end designer.
cat file1.html file2.html file3.html > newfile.html
Edit
This may be easier
find . -name="*.html" | xargs cat >> ../newfile.html
Note that newfile.html is pushed up from the current directory so it is not cat'ed into itself.
Well, if you're not concerned about the resulting file being correct, cat seems like the easiest way to go:
cat file1.html file2.html file3.html > result.html
But of course each of those files with have an <html> tag at the top and a closing one at the bottom, so it won't be a valid HTML file. Firefox will probably load it, but I don't know how it will display it... perhaps only the first one?
You cold always use grep to search something in a group of files instead of merging all of the files and then searching that one file.
grep <string you are looking for> <folder containing all of files> -r
for file in `ls *.html`; do cat "$file" >> output.html; done