awk command

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?

{ 0 comments }

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?

{ 10 comments }

The top and free command display the total amount of free and used physical and swap memory in the server. How do I determine which process is using swap space under Linux operating systems? How do I find out swap space usage of particular process such as memcached?

{ 7 comments }

I have a data as follows :

foo bar 12,300.50
foo bar 2,300.50
abc xyz 1,22,300.50

How do I replace all , from 3rd field using awk and pass output to bc -l in the following format to get sum of all numbers:
12300.50+2300.50+1,22,300.50

{ 8 comments }

I have a sample data file:


This is a test.
Unix is Best.
No Linux is the Best.
Space in simple understanding is an area or volume.
Outer space .

I need the output:

Unix is Best.
Outer space .

How do I print all lines that have three (3) words only?

{ 2 comments }

I‘m trying to match words using GNU awk command and getting the following error:

echo 'foo bar this that blah' | awk '{gsub("\<regex-word\>", "NEW-WORD");print}'

But getting the following warning on screen and it is not working:
awk: warning: escape sequence `\<' treated as plain `<'
awk: warning: escape sequence `\>' treated as plain `>'

How do I fix this problem under Unix like operating systems?

{ 0 comments }

I‘ve a file as follows:

This is a test.
One bang two three
Foo dang Bar
001 0xfg 0xA
002 0xA foo bar 0xfG
I'm done

How do I delete all “words” from the above file which ends with a particular letter (say ‘g’) in each line? The output should be as follows:

This is a test.
One two three
Foo Bar
001 0xA
002 0xA foo bar
I'm done

How do I delete regex-based word using sed or awk under Linux / Unix like operating systems?

{ 6 comments }