How to read these data from a file in JAVA

I have this format of data

p1(x1) p1(x2) imp(p1)
p2(x1) p2(x2) imp(p2)
: : :
pl(x1) pl(x2) imp(pl)
q1(x1) q1(x2) imp(q1)
q2(x1) q2(x2) imp(q2)
: : :
qr(x1) qr(x2) imp(qr)

where n, l(number of p’s) , and r(number of q’s) are integers. I know how to read only integers from a file but how I can read the lines that includes strings and get the values of x1, x2, and p1 for each line?! Thanks in Advance.

Here is my code for reading integers only.

try {
            reader = new BufferedReader(new FileReader(file));
            String text = null;
            while ((text = reader.readLine()) != null) {
                // The first line gives the number of nodes (You will use to create the int[][] graph = new int[nOfNodes][nOfNodes];)
                if (c == 0) {
                    numberOfNodes = Integer.parseInt(text.trim());
                } // The second one gives the number of edges
                else if (c == 1) {
                    nOfEdges = Integer.parseInt(text.trim());
                    graph2 = new double[nOfEdges][3];
                } // And third the list of special nodes
                // `nodes` will now contains only your special constrained one
                else if (c == 2) {
                    String[] str = text.split(" ");
                    for (int i = 0; i < str.length; i++) {
                        if (str[i].trim().length() > 0) {
                } else { // Then you have your edges descriptors
                    String[] str = text.split(" ");
                    for (int i = 0; i < str.length; i++) {
                        if (str[i].trim().length() > 0) {
                            graph2[c - 4][i] = Double.parseDouble(str[i]);
        } catch (FileNotFoundException e) {
        } catch (IOException e) {
        } finally {
            try {
                if (reader != null) {
            } catch (IOException e) {


Using matcher class like this

public static int numberOfPoints = -1, p=-1, q=-1;

    public static void main(String[] args) throws FileNotFoundException {

        ArrayList<Integer> dots = new ArrayList<>();
        int c = 0;
        File file = new File("D:\\ALGORTHIMS\\MASTER LEVEL\\dr. khaled\\assignment 3\\a.txt");
        BufferedReader reader = null;

        try {
            reader = new BufferedReader(new FileReader(file));
            String text = null;
            while ((text = reader.readLine()) != null) {

                try {
                    { numberOfPoints=Integer.parseInt(text); c=1;}
                    { p=Integer.parseInt(text);c=2;}

                } catch (NumberFormatException e) {

                    Matcher m = Pattern.compile("\\(([^)]+)\\)").matcher(text);
        while (m.find()) {



        } catch (FileNotFoundException e) {
        } catch (IOException e) {
        } finally {
            try {
                if (reader != null) {
            } catch (IOException e) {

ansible: include variable file based on the first onne available

You can use the following snippet to achieve the above:

- include_vars: "{{ item }}"
  - "{{ ansible_distribution }}{{ ansible_distribution_major_version }}.yml"
  - default.yml

logrotate: without changing log file

The sample logrotate conf file that we write is as below:

/var/log/sample.log {
    rotate 52
    create 0644 root root
    su root root

You can test it with logrotate -f /etc/logrotate.d/sample

If a process is still writing into sample.log rotating it will create a new sample.log and change its inode.You can check the inode of a file with the command ls -i sample.log If the inode changes then the process keeps writing the log into a buffer and not to the newly created file.

Thus you will need to replace:
create 0644 root root



Automating Slapd Install

You could execute the following command:

export DEBIAN_FRONTEND=noninteractive
debconf-set-selections <<< ‘slapd/root_password password 123123’
debconf-set-selections <<< ‘slapd/root_password_again 123123’
apt-get install slapd ldap-utils -y

Or for a more complex installation you can use:
cat > /root/debconf-slapd.conf << ‘EOF’
slapd slapd/password1 password admin
slapd slapd/internal/adminpw password admin
slapd slapd/internal/generated_adminpw password admin
slapd slapd/password2 password admin
slapd slapd/unsafe_selfwrite_acl note
slapd slapd/purge_database boolean false
slapd slapd/domain string
slapd slapd/ppolicy_schema_needs_update select abort installation
slapd slapd/invalid_config boolean true
slapd slapd/move_old_database boolean false
slapd slapd/backend select MDB
slapd shared/organization string ETH Zurich
slapd slapd/dump_database_destdir string /var/backups/slapd-VERSION
slapd slapd/no_configuration boolean false
slapd slapd/dump_database select when needed
slapd slapd/password_mismatch note
export DEBIAN_FRONTEND=noninteractive
cat /root/debconf-slapd.conf | debconf-set-selections
apt install ldap-utils slapd -y

The possible attributes for debconf-set-selections are defined in the slapd.templates file in the debian package, together with a description of what the configuration attribute is about.

For slapd on Debian Jessie, you can find the file here:


jenkins: zip directory

Install the plugin: File Operations Plugin

Then in the project configuration in Build step add “File operations”

Then click on File zip and give folder location. It will zip it with same name in workspace.


cannot create directory : Permission denied

I had created a directory mkdir xyz with user centos

The following is the output of ll command:
drw——-. 2 centos centos 6 Oct 6 06:11 xyz

When I executed cd xyz I received the following error:
bash: cd: xyz/: Permission denied

I could not access the directory in any case
mkdir xyz/abc
touch xyz/test.txt
All returned the same error.

The solution for this is to add +x permission on the directory.
chmod 700 xyz/
Then I could cd into the directory and create files and folders.

The logic behind this is as belows:

Read bit = If set, you can read this list. So, for example, if you have a directory named poems:

  • You can ls poems and you’ll get a list of items living within (-l won’t reveal any details!).
  • You can use command-line completion i.e. touch poems/so <TAB> poems/somefile.
  • You cannot make poems your working directory (i.e. cd into it).

Write bit = If set, you can modify this list i.e. you can {add,rename,delete} names on it. But! You can actually do it only if the execute bit is set too.

Execute bit = Make this directory your working directory i.e. cd into it. You need this permission if you want to:

  • access (read, write, execute) items living within.
  • modify the list itself i.e. add, rename, delete names on it (of course the write bit must be set on the directory).

Interesting case 1: If you have write + execute permissions on a directory, you can {delete,rename} items living within even if you don’t have write perimission on those items. (use sticky bit to prevent this)

Interesting case 2: If you have execute (but not write) permission on a directory AND you have write permission on a file living within, you cannot delete the file (because it involves removing it from the list). However, you can erase its contents e.g. if it’s a text file you can use vi to open it and delete everything. The file will still be there, but it will be empty.

So the solution is to add +x to the directory.
You will be able to cd into the directory even if you don’t have +x if you are the root user.

Pyinotify – Monitor Filesystem Changes in Real-Time in Linux

Pyinotify is a simple yet useful Python module for monitoring filesystems changes in real-time in Linux.

As a System administrator, you can use it to monitor changes happening to a directory of interest such as web directory or application data storage directory and beyond.

It depends on inotify (a Linux kernel feature incorporated in kernel 2.6.13), which is an event-driven notifier, its notifications are exported from kernel space to user space via three system calls.

The purpose of pyinotify is to bind the three system calls, and support an implementation on top of them providing a common and abstract means to manipulate those functionalities.

In this article, we will show you how to install and use pyinotify in Linux to monitor filesystem changes or modifications in real-time.


In order to use pyinotify, your system must be running:

  1. Linux kernel 2.6.13 or higher
  2. Python 2.4 or higher

How to Install Pyinotify in Linux

First start by checking the kernel and Python versions installed on your system as follows:

# uname -r 
# python -V

Once dependencies are met, we will use pip to install pynotify. In most Linux distributions, Pip is already installed if you’re using Python 2 >=2.7.9 or Python 3 >=3.4 binaries downloaded from, otherwise, install it as follows:

# yum install python-pip      [On CentOS based Distros]
# apt-get install python-pip  [On Debian based Distros]
# dnf install python-pip      [On Fedora 22+]

Now, install pyinotify like so:

# pip install pyinotify

It will install available version from the default repository, if you are looking to have a latest stable version of pyinotify, consider cloning it’s git repository as shown.

# git clone
# cd pyinotify/
# ls
# python install

How to Use pyinotify in Linux

In the example below, I am monitoring any changes to the user tecmint’s home (/home/tecmint) directory as root user (logged in via ssh) as shown in the screenshot:

# python -m pyinotify -v /home/tecmint

Monitor Directory Changes

Next, we will keep a watch for any changes to the web directory (/var/www/html/

# python -m pyinotify -v /var/www/html/

To exit the program, simply hit [Ctrl+C].

Note: When you run pyinotify without specifying any directory to monitor, the /tmp directory is considered by default.