≡ Menu

awk command

Linux: Log Everyone Out Of The System

I can login as root user on Debian or Ubuntu/RHEL/CentOS Linux based system. I need to log everyone off (all ssh users) to install new kernel and/or hardware. How do I do this on Linux? What is the best way to logout ALL USERS remotely over the ssh based session in Linux like operating systems?
[click to continue…]

I am using awk to grep 'foo' from a text file and cacluate sum of field # 7. But, result is rounded to an integer. I need exact result such as 385858.66 and not 385858 using the following command:

grep 'foo' 2012-2013.txt | awk 'BEGIN{ sum=0.0}{ sub(",","",$7); sum +=$7}END{ print "$" sum}'
$682444

Tutorial details
DifficultyEasy (rss)
Root privilegesNo
Requirementsawk
Estimated completion time5 minute
I want $682444.57 as output. How can I force "awk" to do floating point math?
[click to continue…]

sed Tip: Delete All Blank White Spaces

I have a text file as follows:

   foo
   bar
  foobar 

How can I delete all leading and/or trailing blank spaces, tab from each line using sed command?
[click to continue…]

Linux / Unix: Shell Remove Empty Lines

I am a new Linux user. I have text files with lots of empty lines. How do I delete all empty lines under Linux or Unix operating systems?
[click to continue…]

AWK: Remove All Blank Spaces From String / Field

I need to parse the following text file:

# example.net config
user = www30021
group = ftp30020
uid = 30021
gid = 30020
tmp_path = /netapp42/shared/www/images/host.example.com/tmp.bin
tmp_perms = defaults,nodev,nosuid,noexec
jail = on
location = /jails/apache/h/host.example.com/
sftp = on
ftps = off
php-cgi = on
perl-cgi = off

Tutorial details
DifficultyEasy (rss)
Root privilegesNo
Requirementsawk
Estimated completion timeN/A
I need to find out value for each field and remove any blank spaces / white spaces from the field. How do I solve this problem using awk under Linux or Unix like operating systems?
[click to continue…]

Linux / Unix: Add Line Numbers To Files

I know how to display line numbers using vim text editor. How do display line numbers in the left side for any text file under Unix or Linux operating systems?
[click to continue…]

Unix / Linux: Show First 10 or 20 Lines Of a File

I have a directory with many files. I am trying to write a shell script that will only show first 10 or 20 lines of a file. How do I display first 10 or 20 lines of a file on Linux or Unix-like systems?
[click to continue…]