cat, grep, cut, sed and awk to get data about your system - Linux

Published: 14 February 2023
on channel: Rabi Gurung
1,543
41

Learn how to use cat, grep, cut, sed and awk to get data about your system.
We will be trying to get the "Total usable memory" from the /proc/meminfo file just to demonstrate this.

Here are the commands used in this video.

cat /proc/meminfo

cat /proc/meminfo | grep MemTotal

cat /proc/meminfo | grep MemTotal | cut -d: -f 2

cat /proc/meminfo | grep MemTotal | cut -d: -f 2 | sed 's/^ *//g'

^ denotes that what appears after the ^ must appear at the beginning of the pattern space.
$ is the same as ^, but refers to end of pattern space. $ also acts as a special character only at the end of the regular expression or subexpression (that is, before \) or \|), and its use at the end of a subexpression is not portable.
* means what matches a sequence of zero or more instances of matches for the preceding regular expression

cat /proc/meminfo | grep MemTotal | cut -d: -f 2 | sed 's/^ *//g' | cut -d ' ' -f 1

cat /proc/meminfo | grep MemTotal | cut -d: -f 2 | sed 's/^ *//g' | cut -d ' ' -f 1 | awk '{print $0*1024}'

cat /proc/meminfo | grep MemTotal | cut -d: -f 2 | sed 's/^ *//g' | cut -d ' ' -f 1 | awk '{print $0*1024" bytes"}'

cat /proc/meminfo | grep MemTotal | cut -d: -f 2 | sed 's/^ *//g' | cut -d ' ' -f 1 | awk '{print $0*1024" bytes"}' abc.txt


YOUTUBE

#linux #ubuntu #bash #shell #script


Watch video cat, grep, cut, sed and awk to get data about your system - Linux online without registration, duration hours minute second in high quality. This video was added by user Rabi Gurung 14 February 2023, don't forget to share it with your friends and acquaintances, it has been viewed on our site 1,543 once and liked it 41 people.