awk command

I can login as root user on Debian or Ubuntu/RHEL/CentOS Linux based system. I need to log everyone off 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?

{ 6 comments }

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

I want $682444.57 as output. How can I force “awk” to do floating point math?

{ 1 comment }

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?

{ 5 comments }

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?

{ 3 comments }

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

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?

{ 6 comments }

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?

{ 1 comment }

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?

{ 0 comments }