Sunday, 23 February 2014

How to Change Ethernet Media Speed for AIX

How to Change Ethernet Media Speed for AIX

How to Change Ethernet Media Speed for AIX
First you need to find out the device name of your Ethernet card. It should be ent0 if the machine has only 1 Ethernet card. Otherwise, it may be a higher number.

You can determine the legal values for the media speed of the card by running the following command (where the value of ent0 may be different if you machine has multiple Ethernet cards).
lsattr -R -l ent0 -a media_speed
If this command results in the following error—
lsattr: 0514-528 The "media_speed" attribute does not exist in the predefined 
 device configuration database.
—then the Ethernet card is a 10Mbps card that will only do 10Mbps/half duplex

If you do have a 100Mbps card, the lsattr command will return something like this:
These are the media speeds the card will understand. To see the cards current media speed setting you can run
lsattr -EH -l ent0 -a media_speed
To change the media speed, run:
chdev -P -l ent0 -a media_speed=100_Half_Duplex
The value for media_speed can be any of the values listed by the lsattr -R command above. The change does not take effect until you reboot the machine.

If you select a value other than Auto_Negotiation the switch port the machine is connected to must have the same configuration. If the switch and the machine do not match you may get no network connectivity or poor performance.

How to collect test case for VIOs Issues

How to Collect Testcase for Problem Determination on a PowerVM Virtual I/O Server Environment

How to collect test case for VIOs Issues
This article  describes how to gather a testcase on a PowerVM Virtual I/O Server (VIOS) environment to diagnose issues related to

  • Virtual SCSI
  • Virtual Ethernet
  • Virtual Fibre Channel (NPIV) and/or
  • Active Memory Sharing (AMS) also known as virtual memory
Note: This applies to VIOS level 2.2 and above.
There are some know issues you can check here  Link

Testcase collection involves below steps

NOTE: If the testcase being collected is to diagnose issues specific to virtual SCSI, it is very important that you FIRST collect the snap from the VIO server(s), and then the AIX client(s) in question.

1. How to gather snap from VIO server(s)

How to gather snap from VIO server(s)
Login to VIO server, as padmin, and collect snap by running
$ snap

Upon completion, this will create /home/padmin/snap.pax.Z. If this file exists prior to running snap command, it will be deleted and recreated.

Repeat this for any additional VIO server.

Next, rename the compressed file using the following naming convention if you are submitting snaps for more than one vio server:
$ mv snap.pax.Z vios#.snap.pax.Z

2.How to gather snap from AIX client(s)

How to gather snap from AIX client(s)
Login to AIX server, as root and run

# snap -r (this will remove any previous snap)
# snap vfc_client_collect (for virtual fiber channel adapter mapping)
# snap -ac (this will create /tmp/ibmsupt/snap.pax.Z)

Rename the compressed file using a naming convention similar to the the VIO sever snap (i.e vioc#.snap.pax.Z).

Repeat this for any additional AIX client. 

3.1 How to gather virtual mapping (lshwres) data from HMC

The following procedure requires access to an AIX host with secure shell (ssh) configuration to access the HMC. Note: the HMC must be configured to accept ssh connections.
How to gather virtual mapping (lshwres) data from HMC
Login to AIX server, as root, and issue

# script -a /tmp/lshwres.out
# ssh -l hscroot

Once logged in to the HMC issue
# lshmc -V
# lssyscfg -r sys -F name (to list all managed system names)

Run the appropriate lshwres command that relates to your problem

    To gather virtual SCSI mapping, run
    # lshwres -r virtualio -m --rsubtype scsi --level lpar

    To gather virtual fiber channel (NPIV) mapping, run
    # lshwres -r virtualio -m --rsubtype fc --level lpar

    To gather virtual memory sharing (AMS) mapping, run
    # lshwres -r mempool -m
    # lshwres -r mempool -m --rsubtype pgdev

    To gather virtual ethernet mapping, run
    # lshwres -r virtualio -m --rsubtype eth --level lpar

# exit (from the HMC)
# exit (to end the script) 

3.2 How to gather virtual mapping (lshwres) data from IVM

How to gather virtual mapping (lshwres) data from IVM
Login to IVM (VIOS) server, as padmin, and run

$ lssyscfg -F name -r sys (to list all managed system names)
$ oem_setup_env
# script -a /tmp/lshwres.out
# su - padmin

Run the appropriate lshwres command that relates to your problem

    To gather virtual SCSI mapping, run
    $ lshwres -r virtualio -m --rsubtype scsi --level lpar

    To gather virtual fiber channel (NPIV) mapping, run
    $ lshwres -r virtualio -m --rsubtype fc --level lpar

    To gather virtual memory sharing (AMS) mapping, run
    # lshwres -r mempool -m
    # lshwres -r mempool -m --rsubtype pgdev

    To gather virtual ethernet mapping, run
    $ lshwres -r virtualio -m --rsubtype eth --level lpar

$ exit (from padmin shell)
# exit (to end the script) 

4. How to package the testcase

Once the files on section 1-3 have been created, ftp them to a host (i.e. AIX server) to compress them into a single file as follows:
How to package the testcase

In AIX host, as root:

# mkdir /tmp/viotc (ftp the files to this directory)
# cd /tmp/viotc
# ls -la (ensure all files are listed: vio server snap(s), client snap, and lshwres.out)

To create a single file, you can use either the pax or tar command:

# pax -wf pmr#.branch#.countrycode.pax ./* OR
# tar -cvf pmr#.branch#.countrycode.tar ./*

For example, if your pmr is 12345.999.000 (where 12345 is the pmr#, 999 is the branch#, and 000 is the US country code), you would do something similar to the following

    # pwd

    # ls -la
    total 44848
    drwxr-xr-x 2 root system 256 Sep 04 08:27 .
    drwxrwxrwt 12 bin bin 4096 Sep 04 08:27 ..
    -r--r--r-- 1 root system 880 Sep 04 08:07 lshwres.out
    -rw------- 1 root system 7648755 Sep 04 08:10 vioc1.snap.pax.Z
    -rw------- 1 root system 7648755 Sep 04 08:09 vios1.snap.pax.Z
    -rw------- 1 root system 7648755 Sep 04 08:09 vios2.snap.pax.Z

    # pax -wf 12345.999.000.pax -x pax ./*
    # ls -la
    -rw-r--r-- 1 root system 22958080 Sep 04 08:36 12345.999.000.pax
    This is the file you need to send in.


    # tar -cvf 12345.999.000.tar ./*
    a ./lshwres.out 2 blocks.
    a ./vioc1.snap.pax.Z 14939 blocks.
    a ./vios1.snap.pax.Z 14939 blocks.
    a ./vios2.snap.pax.Z 14939 blocks.
    # ls -la
    -rw-r--r-- 1 root system 22958080 Sep 04 08:29 12345.999.000.tar

5. Where to submit the testcase

Where to submit the testcase
login: anonymous
ftp> cd /toibm/aix
ftp> prompt
ftp> binary
ftp> put .pax
ftp> quit

To Upload the Testcase via Secure File Transfer

-> Go to
-> click on toibm, then aix
-> browse for the file and click on 'Upload File (Binary)'

Known Issues:

1. snap svCollect hangs gathering vasi data
IZ90645 - VIOS 2.2 (AIX 6100-06)
IZ91752 - VIOS 2.2.1.x (AIX 6100-07) 

Friday, 21 February 2014

AIX livedump


What is a livedump file system and how is it created


What is an AIX livedump
The concept of an AIX livedump was introduced in AIX 6.1. A livedump is a small dump initiated on a running server and does not require a system restart. The dumps are saved to /var/adm/ras as a default directory and have a file extension that ends in .DZ. Lived dumps are part of an ongoing initiative by AIX called RAS, or reliability, accessibility, and serviceability.

Only components registered with the AIX kernel can be dumped. They can be initiated from software programs by the kernel, a kernel extension, or from the command line. The dump has either a critical or informational priority. The errdemon records an entry in /var/adm/ras/errlog when a livedump occurs.

The LVM kernel component often registers informational livedumps. These can be triggered by multiple LVM errors which have to do with I/O subsystem problems. LVM related livedumps can usually be disregarded because of this and the reason why LVM is having an issue should be investigated.

While a livedump is being written the system is frozen as data is written to pinned memory. The system is unfrozen for the copy to the livedump file system. livedumps are typically very small so the freeze time is a very short interval. At this time livedumps are written serially, not in parallel.

livedump in the Error Report
This is an example of a livedump as shown in the output of "errpt -a":
Date/Time:       Wed Nov  6 08:42:43 2013
Sequence Number: 3550
Machine Id:      000CF31BD400
Node Id:         p260vio1
Class:           S
Type:            INFO
WPAR:            Global
Resource Name:   livedump
Live dump complete
Detail Data
File name and message text

This entry notes that this is an informational livedump, shows where it is located, how it is named, and shows that it was generated by the emfcdd kernel component. An error writing a livedump may report LDM_DUMPERR to the errorlog.

AIX livedump data is gathered by the snap command when using the "-D" option and is stored in a directory called dumpdata.
AIX livedump File Systems
A brand new installation of AIX 6.1 or 7.1 will, by default, have an LVM logical volume called livedump which is mounted as a JFS2 file system /var/adm/ras/livedump. The file system has a default size of 64MB or 1/4 of system memory, whichever is less. However the LVM partition size is also a determining factor in the size of this file system.

A migration from an earlier version of AIX will not create this file system although a directory may be created under /var/adm/ras.

The crontab for root runs dumpcheck at 3:00 PM daily. One of the checks it makes is whether free space in /var/adm/ras/livedump is greater than the livedump_ threshold, which is set to 25% of the file system space as a default value. If there is insufficient space then a message with the label of DMPCHK_LDMPFSFULL will be written to the AIX error log. If the /var/adm/ras/livedump file system does not exist or is not mounted the check will be made against /var.

If a livedump file system does not exist it can be created as follows:

Livedump Creation
1. It will need a minimum of 256MB in space

2. Type "lsvg rootvg" and look at FREE PPs and PP_SIZE. to make sure sufficient space exists in the rootvg to create the livedump logical volume. If the rootvg is mirrored you will need to take this into account.

3. Create and mount the file system. The following example assumes a PP_SIZE of 64MB.

# mklv -t jfs2 -y livedump rootvg 4
# crfs -v jfs2 -d /dev/livedump -m /var/adm/ras/livedump -A yes

If the mount point does not exist create it and then mount the file system.
# mkdir /var/adm/ras/livedump
# mount /var/adm/ras/livedump

4. If you need to mirror the livedump logical volume, type

# mklvcopy livedump 2
# syncvg -l lvedump

IBM AIX- Admin Best Practices

 IBM AIX- Admin Best Practices

When I  was started my career as AIX Admin, it was like  Greek and Latin, so scared . I am not aware where,how  to start .

In this article, I will walk you  through  best practices as  AIX admin  which  makes your life easy.

These are also  applicable to other flavors of Unix Administration  ( like Solaris,Linux & HP-UX) , the only difference some of commands differs to flavour to flavor..

Rule 1:  Learn Process

If you pass this area it would be get very much easy life going forward.

I would like emphasize  on below points especially.

  • Follow ITIL processes which are adopted by most of the companies.
  • Get to know about the SLAs ( Service Level Agreement)
  • Always try to acknowledge tickets as per SLA  and update on regular intervals
  • If its P1 login to bridge call and voice out your findings promptly and wisely
  • Always perform  approved changes within the prescribed change window
Table describes different ITIL process in short.

Process Name
Incident/Ticket Management
An unplanned interruption to an IT Service or a reduction in the Quality of an IT Service. Failure of a Configuration Item that has not yet impacted Service is also an Incident.
P1,P2,P3 & P4
Maximo,BMC Remedy,HP-Service Manager ,Peregrine
Change Management
A process to control and coordinate all changes to an IT production environment.
Normal,Urgent,Emergency &Expedite
Maximo,BMC Remedy,HP-Service Manager ,Peregrine
Service Request /Task Management
A monitoring and reporting the agreed Key Performance Indicators (KPI) corresponding to the compliance with customer and management.

Maximo,BMC Remedy,HP-Service Manager ,Peregrine
Problem Management
Problem Management includes the activities required to diagnose the root cause of incidents identified through the Incident Management process, and to determine the resolution to those problems

Maximo,BMC Remedy,HP-Service Manager ,Peregrine
Release management
Process of managing software releases from development stage to software release.

Rule 2: Get to know Coverage Area & Contacts

  • Make supported servers inventory: If possible make sheet in such way that it includes environment,jump server,application,datacentre location and console information.
  • Get the access for the servers
  • Collect vendor contact information with phone numbers
  • Also keep application team contact information handy

Rule 3: Day to day operations


  • Take system backup mksysb on regularly atleast for one week and keep it in  other server preferably in NIM server
  • Verify mksysb with “lsmksysb -l -f /mksysbimg”(check size).
  • Check the /etc/exclude.rootvg to see if any important filesystem/dir is excluded from the mksysb backup.
  • Ensure  file systems (non-rootvg )backups as per backup software of your company. ( Eg: TSM or Net backup)
  • Take system snap for every week ( make cron entry) and keep log file in different server or make a copy in your desktop

System Consistency Checks:

  • Ensure the current OS level is consistent:     “oslevel -s;oslevel -r;instfix -i|grep ML;instfix -i|grep SP;lppchk -v” [If the os is inconsistent, then first bring the os level to consistent state and then proceed with the change].
  • Proactively remediate compliance issues.
  • Check your firm policies on server uptime and arrange for reboot , generally some organizations  fix it as < 90 days / < 180 days period .

Troubleshooting issues:

  1. Don't do issue fixing without a proper incident record.
  2. Engage relevant parties while working on  the issue
  3. Always try get the information about the issue from the  user ( requestor) with questions line "what, when, where"
  4. Look at errpt first
  5. Check  ‘alog -t console -o’ to see if  its boot issue
  6. Also looking log files mentioned in  "/etc/syslog.conf" , may give some more information for investigation.
  7. Check backups if your looking for configuration change issues
  8. if  your running out of time,involve your next level team and managers
  9. Take help from vendors like IBM,EMC,Symantec if necessary

P1 issues:  

if its a priority 1 (P1) issue you may need to consider few more additional points apart from  above.
  1. On sev1 issues, update the SDM (Service Delivery Manager) in the ST/Communicator  multi chat  at regular intervals.
  2. Over the conference  voice call(bridge call ), if they verbally request you to perform any change, get the confirmation in writing in the multi ST chat.
  3. Update the incident record ( IR) in regular intervals.
  4. Update your team with the issue status(via mail).
  5. Document any new leanings(from issues/changes) and share it with team.

Working on a Change:

Thumb Rule: Change should go in sequence manner DEV ==> UAT/QA==> PROD environment servers.
  1. Make sure change record is in fully approved otherwise don't start any of your task
  2. Ensure proper validated CR procedure is in place;  Precheck -> Installation -> Backout -> Post-Verification
  3. Supress alerts if needed
  4. Remember Application/Database teams are responsible for their Application/Database backup/restore and stop/start. Therefore alert the application teams .
  5. Check the history of the servers(CRs or IRs )…to see if there were any issues or change failures for these servers.
  6. EXPECT THE UNEXPECTED : Ensure you have the proper back out plan in place.
  7. Ensure you are on right server('uname -n'/'hostname') before you perform change.
  8. Make sure your id as well as root id is not expired and working.
  9. Ensure  no other from your team are working on the same task to avoid one change being performed by multiple SAs. Its better to verify with the ‘who -u’ command, to see if there are any SAs already working on the server.
  10. Remember one change at onetime; multiple changes could cause problems & can complicate troubleshooting.
  11. Ensure there are no other conflicting changes from other departments such as SAN, network, firewall, application.. which could dampen your change.
  12. Maintain/record the commands run/console output in the notepad(named after the change).

if its configuration change:

  • Take backup of pre and post values and document them
  • Take screenshots if you comfortable in taking
  • If your are updating configuration of  a file take                                                                                                                              #cp -p <filename> filename_`date +"%m_%d_%Y_%H:%M`"

if its a change to reboot or update s/w :

  1. Check if the server is running any cluster (HACMP/PowerHA), if so then you have to follow different procedure.
  2. Always remember three essential things are in place before you perform any change “backup(mksysb); system information; console”
  3. Take system configuration information (sysinfo script).
  4. Check the lv/filesystems consistency “df -k”(df should not hang); all lvs should be in sync state “lsvg -o|lsvg -il”.
  5. Check errpt & ‘alog -t console -o’ to see if there are any errors.
  6. Ensure latest  mksysb(OS image backup) kept in relevant NIM server
  7. Ensure  non-rootvg file systems backup taken
  8. Verify boot list & boot device:   “bootlist -m normal -o”  “ipl_varyon -i”
  9. Login to HMC console
Additional points for reboot:
  1. Put the servers in maintenance  mode (stop alerts) to avoid unnecessary incident alerts.
  2. Check filesystems count “df -g|wc -l”  ; verify the count after migration or reboot.
  3. Ensure there are no schedule reboots in crontab. If there is any then comment it before you proceed with the change.
  4. If the system has not rebooted from long-time(> 100 days); then perform ‘bosboot’ & then reboot the machine(verify the fs/appfs after reboot), & then commence with the migration/upgrade. [Don't reboot the machine if the bosboot fails!]
  5. Look for the log messages carefully; don't ignore warnings.
Additional points for OS & S/W upgrades:
  1. Ensure hd5(bootlv) is 32MB (contiguous PPs)  [very important for migration]
  2. For OS updates Initiate the change on console. If there is any network disconnection during the change, you can reconnect to the console and get the menus back.
  3. If situation demands ,ensure there is enough free filesystem space(/usr, /var, / ), required for the change.
  4. Have the patches/filesets pre-downloaded and verified.
  5. Check/verify the repositories on NIM/central server; check if these repositories were tested/used earlier.
  6. If there are two disks in rootvg, then perform alt disk clone for one disk. This is fastest & safest back-out method in case of any failure. Though you perform alt disk clone, ensure you as well take mksysb.
  7. For migration change, check if there is SAN(IBM/EMC..) used, if so, then you have to follow the procedure of exporting vgs, uninstall sdd* fileset;and after migration reinstall sdd* fileset, reimport vgs etc.
  8. Perform preview(TL/SP upgrade) before you perform actual change; see if there are any errors reported in preview(look for keyword ‘error’ / ‘fail’); look for the tail/summary of messages;
  9. Though the preview may report as ‘ok’ at the header, still you have to look in the messages and read the tail/summary of preview.
  10. If preview reports any dependency/requisite filesets  missing then have those downloaded as well.
  11. Ensure you have enough free space in rootvg. Min of 1-2 GB to be free in rootvg(TL upgrade/OS migration).
  12. Ensure application team have tested their application on the new TL/SP/OS to which you are upgrading your system.
  13. If you have multiple putty sessions opened; then name the sessions accordingly [Putty -> under behaviour -> window title]; this will help you in quickly getting to the right session or else use PuttyCM ( Putty Connection Manager)
  14. Ensure for TL upgrades, you go by TL by TL, shortcut to direct TL could sometimes cause problem.
What if you are crossing change widow ?
  • inform the relevant application teams and SDMs  and take extended with proper approvals
  • Raise a incident record in supporting the issue.
What if change fails ?
  • Inform the relevant application teams and SDMs
  • Close the record with the facts
  • Attend the change review calls for the failed changes
Successful Change:
  • if possible send the success status to relevant parties  with artifacts
  • Update the change request with relevant artifacts and close it

Last but not the least:

  • Don't hesitate to take your team mates help or vendor support  when your  issue taking more time
  • Inform your managers if the issue in escalation situation ( if its P1 you need to inform prior).
  • Always perform change with proper approvals in place
  • Take backups  and  make your life easy
Happy Unixing Thumbs up

Saturday, 15 February 2014

Regular Expressions Special Characters Explained

Regular expressions” (often shortened to “regex”) is a language used to represent patterns for matching text. Regular expressions are the primary text-matching schema in all text-processing tools, including grep,egrep,awk ,sed.
The following table contains the basic elements, along with description and examples.
Regex Description Example
^ The start-of-line marker ^tux matches any line that starts with tux
$ The end-of-line marker tux$ matches any line that ends with tux
. Matches any one character Hack. matches Hack1, Hacki but not Hack12, Hackil; only one additional character matches
[] Matches any one of the character set inside [] coo[kl] matches cook or cool
[^] Exclusion set: the carat negates the set of characters in the square brackets; text matching this set will not be returned as a match 9[^01] matches 92, 93 but not 91 and 90
[-] Matches any character within the range specified in [] [1-5] matches any digits from 1 to 5
? The preceding item must match one or zero times colou?r matches color or colour but not colouur
+ The preceding item must match one or more times Rollno-9+ matches Rollno-99, Rollno-9 but not Rollno-
* The preceding item must match zero or more times co*l matches cl, col, coool
() Creates a substring in the regex match Explained below, in the section “Substring match and back-referencing”
{n} The preceding item must match exactly n times [0-9]{3} matches any three-digit number. This can be expanded as: [0-9][0-9][0-9]
{n,} Minimum number of times that the preceding item should match [0-9]{2,} matches any number that is two digits or more in length
{n, m} Specifies the minimum and maximum number of times the preceding item should match [0-9]{2,5} matches any number that is between two and five digits in length
| Alternation — one of the items on either side of | should match Oct (1st|2nd) matches Oct 1st or Oct 2nd
\ The escape character for escaping any of the special characters given above a\.b matches a.b but not ajb. The dot is not interpreted as the special “match any one character” regex shown above, but instead a literal dot (period) ASCII character is sought to be matched. Another example: if you’re searching for the US currency symbol “$”, and not the end-of-line marker, you must precede it with a back-slash, like this: \$
There are a few character classes, called POSIX classes, in the format [:name:] that can be conveniently used, instead of spelling out the character set each time. Note that, as shown in the example column, you need to enclose the class itself in another pair of square brackets. For example:
$ echo -e "maxnORnMatrix" | sed '/[:alpha:]/d'
$ echo -e "maxnORnMatrix" | sed '/[[:alpha:]]/d'
In the first case, the set is interpreted literally — the words max and matrix are deleted because they contain a, one of the letters in the character set. In the second command, with another pair of square brackets around the class, all input lines are deleted, because all lines contain (at least one) alphabet.
Regex Description Example
[:alnum:] Alphanumeric characters [[:alnum:]]+
[:alpha:] Alphabet character (lowercase and uppercase) [[:alpha:]]{4}
[:blank:] Space and tab [[:blank:]]*
[:digit:] Digit [[:digit:]]?
[:lower:] Lowercase alphabet [[:lower:]]{5,}
[:upper:] Uppercase alphabet ([[:upper:]]+)?
[:punct:] Punctuation [[:punct:]]
[:space:] All whitespace characters including newline, carriage return, and so on [[:space:]]+
Meta-characters are a type of Perl-style regular expressions that are supported by a subset of text-processing utilities. Not all utilities will support the following notations.
Regex Description Example
\b Word boundary \bcool\b matches only cool and not coolant
\B Non-word boundary cool\B matches coolant but not cool
\d Single digit character b\db matches b2b but not bcb
\D Single non-digit b\Db matches bcb but not b2b
\w Single word character (alnum and _) \w matches 1 or a but not &
\W Single non-word character \w matches & but not 1 or a
\n Newline \n matches a new line
\s Single whitespace x\sx matches x x but not xx
\S Single non-space x\Sx matches xkx but not x x
\r Carriage return \r matches carriage return
The above tables can be used as a reference while constructing regular expression patterns.
Let us go through a few examples of regular expressions.

Treatment of special characters

Regular expressions use some characters such as $, ^, ., *, +, {, and } as special characters. But what if we want to use these characters as non-special characters (normal text character)? Let’s see an example. Regex: [a-z]*.[0-9].
How is this interpreted? It can be zero or more [a-z] ([a-z]*), then any one character (.), and one character in the set [0-9] such that it matches abcdeO9. It can also be interpreted as one of [a-z], then a character *, then a character . (period), and a digit such that it matches x*.8. In order to overcome this problem, we precede the character with a forward slash \ (doing this is called “escaping the character”). The characters such as * that have multiple meanings are prefixed with \ to make them into a special meaning or to make them non special.
Whether special characters or non-special characters are to be escaped varies depending on the tool that you are using. In short the term special meaning means that a character is considered as meaningful interpretation other than its character ASCII value. For example a*means a, aa, aaa… Here * has special meaning since its not interpreted as ASCII character “*”.
Certain characters to be escaped using \ to give special meaning while some others are by default taken as special meaning (e.g., *). To use it as regular ASCII meaning, it should be escaped. Here is small list of characters having special meaning with escaping: \+, \{, \}, \(,\), \?.
Characters that are by default special (you need to escape these in order to use as regular ASCII): *, ., ^, $, [, ].
To match any line containing only the word test, and no other characters on it, use ^test$. This is interpreted as “start of line marker” followed by “test” followed by “end of line marker”.
Another good example is to extract email addresses from the given text. An email address has the format username@domain.root. We can formulate the regular expression as:
[A-Za-z0-9.]+@[A-Za-z0-9.]+.[a-zA-Z]{2,4}. The [A-Za-z0-9.]+ before @ states that the given character class should occur one or more times, just as after the @. At the end of the email address, we have the TLD (top-level domain), which can be two to four characters in length, as specified by {2,4}.

Points to remember

In Sed, “one or more” (+) is always prefixed with the backslash escape character if it does not occur after a character set/class, while “zero or more” (*) is not thus prefixed. We can do an inverse match using /PATTERN/!{statements}. That is, include the bang (!) after the slash after PATTERN.