≡ Menu

awk command

FreeBSD find the chmod numerical value for a file or directory

I need to find out the numerical value of a file on a FreeBSD system. For example, get 644 instead of -rw-r--r-- for the /etc/resolv.conf file. Is there is a way to get this value in my bash shell script?
[click to continue…]

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…]

Awk Floating Point Number Addition Results Are Unexpected

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}'

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:


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

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…]

Linux / Unix: users Command Examples

users command

I am a new Linux and Unix system user. How do I list current users on Linux or Unix-like operating system using shell prompt?
[click to continue…]

Bash Shell: Remove (Trim) White Spaces From String / Variable

I have a bash variable as follows:

output="$(awk -F',' '/Name/ {print $9}' input.file)"

How do trim leading and trailing whitespace from bash variable called $output? How do I trim trailing whitespace from $output?
[click to continue…]