1

I have a file like below.

 1. VMware ESX
 2. SCCM
 3. Healthcare Information Technology
 4. vSphere
 5. Citrix Metaframe
 6. IT Service Management
 7. ITIL
 8. Active Directory
 9. Project Portfolio Management
10. Windows
11. Incident Management
12. Change Management
13. Disaster Recovery
14. Governance
15. Citrix
16. Stakeholder Management
17. Project Delivery
18. IT Operations
19. Infrastructure

I want only the values after . I need only the values like VMWare ESX, SCCM etc to store in an array.

I tried the below command.

echo $line | grep -o -P '.'

But it is giving me characters before dot.

4

To remove the characters before and including the right-most occurrence of a dot followed by a space.

sed 's/.*\. //' < file

If .␣ may appear more than once and you only want to remove up to the first occurrence, the trick is to do:

sed 's/\. /\
/;s/.*\n//' < file

(that is replace the first occurrence with a newline character, and then remove everything up to that newline).

However, in your case,

sed 's/^[^.]*\. //' < file

(remove a leading sequence of non-dot characters followed by a dot and a space).

or even:

cut -c5- < file

(remove the first 4 characters) should be enough.

Using GNU grep with support for recent PCRE:

grep -Po '\. \K.*'
2

Use

sed 's/.*\.\ //' your-file-name

to remove the characters before and including the dot followed by space.

1

In awk:

awk -F'. ' '{$1=""; print $0}' your_file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.