Category Archives: How to Fix

Grep finds all files containing a string in Linux

In projects, it is common to encounter cases such as original table names that have been changed and need to be replaced in batches in scripts. But what tables are involved, looking them up one by one is a bit of a hassle and you might miss them; Replacing directly on Linux may not perform good version synchronization; So, consider using a combination of find and the grep command to find out which scripts need to be modified before unifying the processing.

--递归查找目录下含有该字符串的所有文件
grep -rn "data_chushou_pay_info"  /home/hadoop/nisj/automationDemand/

--查找当前目录下后缀名过滤的文件
grep -Rn "data_chushou_pay_info" *.py

--当前目录及设定子目录下的符合条件的文件
grep -Rn "data_chushou_pay_info" /home/hadoop/nisj/automationDemand/ *.py

--结合find命令过滤目录及文件名后缀
find /home/hadoop/nisj/automationDemand/ -type f -name '*.py'|xargs grep -n 'data_chushou_pay_info'

final: [
find/home/hadoop/nisj/automationDemand/-type f – the name ‘*. Py’ | xargs grep -n ‘data_chushou_pay_info’ 】 compared to meet the requirements of the query.

Grep

* : represents all files in the current directory, or a file name

-r is a recursive lookup

-n is the display line number

-r find all files contain subdirectories

-i ignores case

interesting command-line argument:
grep-i pattern files: search case-insensitive. The default case is case sensitive

grep-l pattern files: only the filenames that match are listed, not the path

grep-l pattern files: lists file names that do not match

grep-w pattern files: match whole words only, not parts of strings (for example, match ‘magic’ rather than ‘magical’)

grep-c number pattern files: the matched context displays [number] lines, respectively

grep pattern1 | pattern2 files : displays rows matching pattern1 or pattern2

grep pattern1 files | grep pattern2 : displays lines matching both pattern1 and pattern2

some special symbols for searching:
\< And \ & gt; Mark the beginning and end of each word.

such as:

grep man * will match ‘Batman’, ‘manic’, ‘man’, etc

grep ‘\< Man ‘* matches’ Manic’ and ‘man’, but not’ Batman ‘.

grep ‘\< man\> ‘matches only’ man ‘and not’ Batman ‘or’ manic ‘and other strings.

‘^’ : refers to the beginning of the matched string line

‘$’ : refers to the end of the matching string

Delete the specified crontab timer task under Linux

1. Create two new script files to test

test1.sh

ping 114.114.114.114

test2.sh

ping 8.8.8.8 

2. Edit crontab task by crontab -e command, and add the following contents:

*/1 * * * * /dd/shell/test1.sh
*/1 * * * * /dd/shell/test2.sh

After adding

, check the crontab content:

[root@localhost shell]# crontab -l
*/1 * * * * /dd/shell/test1.sh
*/1 * * * * /dd/shell/test2.sh

added crontab task, in /var/spool/cron directory will have a file named the current login account. Let’s say My login is root. A root file exists. The contents of this file are the crontab tasks that you just added.

[root @ localhost cron] # cat/var/spool/cron/root/1
* * * * */dd/shell/test1. Sh
* * * * */1/dd/shell/test2. Sh

3. Delete test2.sh from crontab

is where sed is used to process the /var/spool/cron/root file and delete the line containing test2.sh.

 sed -i '/test2.sh/d' /var/spool/cron/root 

Crontab -l command after the
command.

[root@localhost shell]# crontab -l
*/1 * * * * /dd/shell/test1.sh

you can see that the task for test2.sh has been removed. Through observation, the steps of test2.sh are no longer performed. Indicates that the deletion was successful.

4. Delete crontab blank line

after executing the sed-i command above, crontab -l will see an extra line of white space. If you feel awkward, you can delete the blank line with the following command: sed.

 sed -i '/^$/d' /var/spool/cron/root


Python export data (CSV format)

Python export CSV data

to_csv(filePath,sep=”,”,index=TRUE,header=TRUE)

sep separator, default to comma (“, “)

index whether to export row serial number, default is TRUE

Whether the

header exports the column name, the default is TRUE

Get the stock data from Tushare library and export

import tushare as ts
df=ts.sh_margins(start=’2015-01-01′, end=’2015-04-19′)
df.to_csv(“d://df.csv”)

df file opens as:


import tushare as ts ab = ts. Sh_margins (start = ‘2015-01-01’, end = ‘2015-04-19’).
ab to_csv (” d:// ab. CSV, “index = False)

if index changes to false, then:

Solve the problem of available for offline mode in Android studio compilation

reprint please indicate the source:
http://blog.csdn.net/aa464971/article/details/68948650

anomaly full text

Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugApkCopy'.
   > Could not resolve com.squareup.okhttp3:okhttp:3.5.0.
     Required by:
         retrofit-rxjava-okhttp:app:unspecified > com.squareup.retrofit2:retrofit:2.1.0
      > No cached version of com.squareup.okhttp3:okhttp:3.5.0 available for offline mode.

solution

screenshot is version 2.2

Settings – Build. Execution, Deployment – Gradle – uncheck the Offline Work, recompile.

Java operation temporary file creation and deletion

in Java’s File class, there is a createTempFile(String prefix,String suffix) that is called to create a temporary File in the system’s default temporary File directory.
prefix means filename.
suffix represents the suffix of a file, in the form “. TMP “, note that “. “

is needed

final File htmlFile = File.createTempFile("temp", ".html");//创建临时文件
logger.info("临时文件所在的本地路径:" + htmlFile.getCanonicalPath());
FileOutputStream fos = new FileOutputStream(htmlFile);
try {
   //这里处理业务逻辑
} finally {
    //关闭临时文件
    fos.flush();
    fos.close();

    htmlFile.deleteOnExit();//程序退出时删除临时文件
}

on win7, the default directory for temporary files is C:\Users\Administrator\AppData\Local\Temp. After
finishes using the temporary file, executing htmlfile.deleteonexit () will automatically delete the temporary file.

Dataframe and np.array The mutual transformation of

the Internet looking for half a day not dataframe into transformation dataframe array is an array, so here to summary the mutual conversion of python generation is as follows:

  • dataframe into array
    df=df.values
    • array into the dataframe
      import pandas as pd
      
      df = pd.DataFrame(df)

      and that’s OK!

Docker encountered a problem 4: yaml: Line 1: mapping values are not allowed in this context

refer to the example of the official document part3 and execute the docker stack deploy-c docker-composer. Yml getstartedlab with the error message as follows:

cappuccinooos-MacBook-Pro:part3 cappuccinooo$ docker stack deploy -c docker-compose.yml  getstartedlab
yaml: line 1: mapping values are not allowed in this context

from the error message can know, is docker – compose. Yml file format has a problem, yml file has strict requirements on the blank space indentation, direct copy the contents of the official document is not enough, the search on the net have tools to online check yml file format, format errors will give corresponding hint, feel quite convenient, and the link below: https://www.bejson.com/validators/yaml/

after modifying the docker-composer. Yml, execute the docker stack deploy-c docker-composer. Yml getstartedlab command successfully

cappuccinooos-MacBook-Pro:part3 cappuccinooo$ docker stack deploy -c docker-compose.yml  getstartedlab
Creating network getstartedlab_webnet
Creating service getstartedlab_web

Tensorflow error: module ‘tensorflow’ has no attribute ‘xxx’

____tz_zs

good tensorflow appears suddenly: can import the tensorflow package, but using any module under tensorflow will report a “nonexistence” error.

such as: using tf.variable to create a Variable also reports AttributeError: module ‘tensorflow’ has no attribute ‘Variable ‘.

because tensorflow becomes a module without any content (the reason why tensorflow becomes empty is unknown)

solution: uninstall tensorflow (based on the PIP uninstall tensorflow or PIP uninstall tensorflow-gpu you installed) and reinstall it (based on the PIP install tensorflow or PIP install tensorflow-gpu you installed)

ps: according to some discussion information found by Google, when tensorflow was installed under Windows, it also appeared that the tensorflow was empty, possibly because of the permission problem.

add:

Windows TensorFlow installation: http://blog.csdn.net/tz_zs/article/details/74779953

making similar discussion: https://github.com/tensorflow/tensorflow/issues/7285

Mongodb start error: child process failed, exited with error number 1

mongodb startup ERROR ERROR: child process failed, exited with ERROR number 1

is usually a problem of permissions, or there is no corresponding path

check step: add a parameter after startup to export the log to a writable directory :

./mongod –fork –logpath=/tmp/mongod.log

then check the problem as follows :

2017-02-22 T01:33:34. 229 + 0800 I CONTROL [main] ERROR: always write a pid file to/var/run/mongo/mongod. Pid: No to the file or directory

means there is no such directory (/var/run/mongodb/)

and I’m just going to create a new mkdir -p /var/run/mongodb/

starts normally again as follows:

root@sz:~/soft/mongodb342/bin#./mongod -f /etc/mongodb/mongod. Conf
about to fork child process, waiting until server is ready for connections.
forked process: 7482
child process started successfully, parent exiting

Win10 can’t drag files to open directly

most people install win10, a lot of software drag and drop files onto the software directly open function failure, then you must use the open function in the software, this is very troublesome. There are two approaches that have been tested.

method 1 (a little more trouble)



  1. 1

    press Windows +R to open the run dialog box: type regedit, enter or ok.

  2. 2

    find the following key values HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system

  3. 3

    , right click “EnableLUA” and select “modify”. Change the value to 0. Ok. Then just restart the machine.

    END

method 2 (faster)



  1. create a new text document on the desktop

  2. open the text document and copy the following text and save.

    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System]

    “EnableLUA”=dword:00000000

  3. 3

    to the document suffix name REG, you can also change the file name, both in Chinese and English can be, for example, I changed to “Win10 can not directly drag files open to solve. REG”. Can put this file is not the system disk to facilitate the next reinstall the system when used.

  4. 4

    double-click the modified file, make sure to import the registry, and then restart the system.

CSS: several ways to center the box vertically and horizontally

method 1: width and height known.

idea:
relative positioning of the parent element
absolute positioning of the child element
left: 50%; top: 50%;
margin-left: negative half width.
margin-top: minus half of the height;

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>居中</title>
    <style type="text/css">
        #box{
            width: 400px;
            height: 200px;
            position: relative;
            background: red;
        }
        #box1{
            width: 200px;
            height: 100px;
            position: absolute;
            top: 50%;
            left: 50%;
            margin-left: -100px;
            margin-top: -50px;
            background: green;
        }
    </style>
</head>
<body>
    <div id="box">
        <div id="box1">

        </div>
    </div>
</body>
</html>

method 2: width and height themselves unknown

means that the subbox itself still has a width and a height that it doesn’t know.
relative positioning of parent box
absolute positioning of child box
top, right, bottom, left all 0
margin: auto;

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>居中</title>
    <style type="text/css">
        #box{
            width: 800px;
            height: 400px;
            position: relative;
            background: red;
        }
        #box1{
            width: 100px;
            height: 50px;
            position: absolute;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            margin: auto;
            background: green;
        }
    </style>
</head>
<body>
    <div id="box">
        <div id="box1">

        </div>
    </div>
    <script type="text/javascript">

    </script>
</body>
</html>

method 3: flex layout

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>垂直居中</title>
    <style type="text/css">
        .box{
            width: 400px;
            height: 200px;
            background: #f99;
        }
        .box1{
            width: 200px;
            height: 100px;
            background: green;
        }
        .center{
            display: flex;
            justify-content: center;//实现水平居中
            align-items: center;//实现垂直居中
        }
    </style>
</head>
<body>
    <div class="box center">
        <div class="box1">

        </div>
    </div>
</body>
</html>

Method 4: translation positioning +transform

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>css3让一个盒子居中</title>
    <style type="text/css">
        .parent_box{
            width: 400px;
            height: 200px;
            background: red;
            position: relative;
        }
        .child_box{
            width: 200px;
            height: 100px;
            background: #9ff;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate( -50%,-50%);
        }
    </style>
</head>
<body>
    <div class="parent_box">
        <div class="child_box">

        </div>
    </div>
</body>
</html>

method 5: table-cell layout

parent display: table-cell; vertical-align: middle; Sub-level margin: 0 auto;

** horizontal center

plus a horizontal center: margin-left: 50%; transform: translateX(-50%);