Tips & Tricks

OpenSource For You - - Contents -

Con­vert­ing a CSV file to a DSV file us­ing the col­umn and cat com­mands

To un­der­stand how to con­vert a CSV file to a DSV file, let’s look at a few ex­am­ples of ESS.csv.

ESS.csv is a comma-sep­a­rated file; its left and right en­clo­sure is ‘“’ and the field sep­a­ra­tor is ‘,’.

Ex­am­ple 1: To con­vert the ESS.csv file to a de­lim­ited file (i.e., dsv) us­ing the col­umn com­mand, try the fol­low­ing com­mand:

cat ESS.csv | col­umn -t -s ‘”’ -o ‘’ | col­umn -t -s ‘,’ -o ‘;’ > ESS.dsv

The above com­mand changes the left and right en­clo­sures from ‘“’ to none and the field sep­a­ra­tor is ‘;’.

You can cus­tomise the left en­clo­sure as per your re­quire­ments.

Ex­am­ple 2: Change the left and right en­clo­sures from ‘“’ to ‘‘’ and the field sep­a­ra­tor is ‘;’.

cat ESS.csv | col­umn -t -s ‘”’ -o ‘’’ | col­umn -t -s ‘,’ -o ‘;’ > ESS.dsv

Ex­am­ple 3: Change the left and right en­clo­sures from ‘“’ to ‘:’ and the field sep­a­ra­tor is ‘;’.

cat ES.csv | col­umn -t -s \’\’\’ -o ‘:’ | col­umn -t -s ‘,’ -o ‘;’ > ES.dsv

Ex­am­ple files are avail­able on GitHub at https://github.com/he­manth22/CSVToCus­tomDSV and at the GitHub Wiki guide https://github.com/ he­manth22/CSVToCus­tomDSV/wiki/Guide-to-useCSVToCus­tomDSV. To down­load an ex­am­ple, use the fol­low­ing com­mand:

git clone https://github.com/he­manth22/CSVToCus­tomDSV.git

—He­manth Bi­tra, he­man­th­bi­tra@bi­troid.in

Re­set­ting a for­got­ten root user ac­count pass­word in Cen­tOS 7/RHEL

We can eas­ily re­set the root user ac­count by boot­ing into the sin­gle mode us­ing the fol­low­ing steps.

Step 1: While boot­ing the sys­tem, you see a screen with two op­tions as shown below:

Cen­tOS Linux, with Linux 3.10.0-123.el7.x86_64 Cen­tOS Linux, with Linux 0-res­cue-27ca624e1d5b47ad97b­ba2bbc 648d347

Use the ar­row keys as soon as you see the screen with the above two op­tions so that a time-out does not take place. Now se­lect the first op­tion and press the ‘e’ key to edit.

Step 2: You will be pre­sented with the ker­nel pa­ram­e­ters’ screen, and you may have to use the ar­row key to see the line where the ‘vm­linuz’ mount point is set. Here, search for the text ‘rhgb quiet’ and re­place this text with ‘init=/bin/bash’ with­out quotes, and press Con­trol+x to boot the sys­tem with this edited con­fig­u­ra­tion.

Step 3: Af­ter boot­ing, you will see what’s shown below:

bash-4.2#

You will di­rectly get the bash shell with root priv­i­leges where you can re­set the root pass­word us­ing the ‘passwd’ com­mand as shown below:

bash-4.2# passwd

You can suc­cess­fully re­set the root ac­count pass­word in this way.

—Sharmin Shaikh, imsharmeen@gmail.com

Never miss the Ubuntu no­ti­fi­ca­tion ‘sys­tem res­tart re­quired’

We must re­boot the server when we in­stall a new ker­nel or li­braries. Ubuntu Linux can tell you if the sys­tem needs a re­boot when you lo­gin as root user.

*** Sys­tem res­tart re­quired ***

The above warn­ing will ap­pear on the lo­gin screen, but we may miss this warn­ing. So here is the sim­ple script for ad­min­is­tra­tors to find out ex­actly when the sys­tem re­quires a re­boot.

You can man­u­ally find the file /var/run/re­bootre­quired, which in­di­cates that a sys­tem res­tart is re­quired.

In­stead of a man­ual search, you can use the fol­low­ing script to iden­tify the Ubuntu no­ti­fi­ca­tion of ‘sys­tem res­tart re­quired’ at ev­ery lo­gin and never miss the warn­ing.

Add the fol­low­ing lines in the file /root/sta­tus.sh: #!/bin/bash if [ -f /var/run/re­boot-re­quired ] then echo -e “33[33;31m[*** Hello $USER, you must re­boot your ma­chine ***]33[0m” else echo -e “33[33;32m\n*** Sys­tem re­boot is NOT re­quired now ***\n`cat /var/lib/up­date­no­ti­fier/up­dates­avail­able`\ n33[0m” fi

Now we can add the file path /root/sta­tus.sh in / root/.bashrc file to check for the ‘Re­boot re­quired’ task at ev­ery lo­gin made by the root user.

# echo “/root/sta­tus.sh” >> /root/.bashrc && tail -n3 / root/.bashrc

—Ran­jithku­mar T, ran­jith.stc@gmail.com

Mul­ti­ple tips for daily use

1. Copy from or paste into the ter­mi­nal in Ubuntu Many peo­ple try to paste into the ter­mi­nal by us­ing Ctrl+v. But this will not work. We need to use Ctrl+Shift+v to paste into the ter­mi­nal. Sim­i­larly, to copy from the ter­mi­nal, se­lect the text to be copied and use Ctrl+Shift+c.

This is the sim­plest and easiest way for new users to over­come the prob­lems of copy­ing and past­ing into the ter­mi­nal.

2. Us­ing ‘tac’ to out­put the con­tents of a file in­stead of ‘cat’

Many peo­ple use the ‘cat’ com­mand to out­put the con­tents on the ter­mi­nal. If the con­tents are huge, then users have to scroll up till they reach the first line of the con­tent. In­stead of scrolling all the way up till the be­gin­ning and scan­ning, users can re­place ‘cat’ with ‘tac’. The lat­ter works just like the ‘cat’ com­mand — the only dif­fer­ence is that the re­sults are printed in re­verse or­der; i.e., the first line comes last and the last line ap­pears first. So users can eas­ily see the first line with­out scrolling all the way to the be­gin­ning.

3. Get­ting to know the per­mis­sions of files us­ing the ‘ls­l’ com­mand on the ter­mi­nal in Ubuntu

One can get to know the per­mis­sion of any file in the sys­tem by ex­e­cut­ing the ‘ls-l’ com­mand on the ter­mi­nal. The per­mis­sions are shown in the first col­umn. r-read, w-write and x-ex­e­cute are per­mis­sions for dif­fer­ent users, i.e., the first three char­ac­ters are to show per­mis­sions of the owner on that file, the next three are for group per­mis­sions and the last three are for oth­ers’ per­mis­sions on that file. There will be an ini­tial ‘-’ be­fore list­ing per­mis­sions of that file. So users can get to know who all can ac­cess the file that they them­selves are us­ing or go­ing to.

As an ex­am­ple, -rwxrw-r-- tells us that there is read, write and ex­e­cute per­mis­sions for the owner; read and write per­mis­sions for the group; and only read per­mis­sion for oth­ers, on the file.

—Anirudh Kalwa, anirudh.3194@gmail.com

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.