Java convert a list to a csv string

Here’s an easy way to convert a list of Strings to a String containing csv values <pre  class=”brush:java”> StringUtils.join(list, ‘,’) </pre> To reverse conversion can be done by – csv to list <pre  class=”brush:java”> Arrays.asList(StringUtils.split(rs.getString(“a,b”), “,”)) </pre>  

Systemd and Systemctl – services, units and run levels

systemd has replaced the univ SysV (System V) and BSD init systems  in majority of the linux distributions. Centos 7 now has systemd and has changed the way services are handled. This is not a comprehensive tutorial but a simple introduction on how services are added, started, enabled, listed and removed using systemctl. Before we … Read more

use awk to add/subtract values from a column in csv file

awk -F “,” ‘{printf “%3.6f,%3.6f\n”,($1 – 1),$2}’ file.txt This command reads a file called file.txt and then subtracts 1 from the first row. %3.6 is used to format the output columns. The output can be redirected to another file.

cat all files recursively in a directory

find . -name ‘*.txt’ -exec cat {} \; This command finds all files that have an extension of .txt in the current directory and its sub directories and executes a cat command on them

Total size of a directory in unix

Use the du command to get the size of a directory du -h prints the size of current directory and each directory under it in a human readable form. To get the size of the current directory only use this command du -sh to get the size of a particular directory du -sh

Cut lines in a file using a delimiter and select specific columns

The cut command is extremely powerful. In this example we look at using the cut command to parse a comma separated file and retrieve columns 1 to 4 cut -d “,” -f -4 -d specifies the delimiter -f specifies which columns to select. In this case we select all columns upto 4 The unix pipe … Read more

read a file in reverse

At times it is required to read a file in reverse. i.e. starting from the last time and reading up. The best way to do this is to use the ‘tac’ command tac filename

Merge multiple text files into another file

One way to merge multiple text files into a new text file is to use the cat command. cat file1.csv file2.csv > file3.csv This command merges file1.csv and file2.csv into a new file called file3.csv we can also append to an existing file instead of creating a new one cat file1.csv file2.csv >> file3.csv This … Read more