Reputation: 777
8167656.COMTXSFR.COMXYSJZT.NET256079.COMG-BEI.NET256702.COM516073.COMWBMSR.COMWCRHC.COMWBRZD.COMWCFGR.COM571095.COM5770879.COMWBRTK.COMYWRTF.COMDZJZPX.COM5770819.COMSFCZH.COM8733918.COMHSPCF.COMSFXHT.COMXJFPX.COMWCRGT.COMWCKYR.COMWBRHM.COMWBRYG.COMWCRGX.COMFXTMY.COM1313661.COMBKRQC.COMBKSQC.COMBLLQC.COM6880797.COMWCKKR.COMWCJKR.COM516097.COMFPCYS.COMDKDZS.COMWIN2010.NETSFMWM.COMFSHUAYUE.NET001DAO.NETEXQUISITEGIFT.NETBANTLN.COMW363888.NET8848K.NETV6789.COMSZJIAHUA.NETICJY.NETSUPVAR.NETHUALINONLINE.NE
That's an example of what I'm working with. I need to add a space after (COM|NET|INFO)
so the domains are readable. I've tried a few different ways, but can't seem to get it to work. The regex should be (\.INFO|\.COM|\.NET)
right?
Upvotes: 0
Views: 50
Reputation: 2116
sed
uses POSIX Basic Regular Expressions, and use of alteration (|
) in BREs is a non-portable extension.
In this case, to substitute for multiple words a substitution (s
) command is needed per-word:
sed 's/\.INFO/& /g;s/\.COM/& /g;s/\.NET/& /g'
&
is substituted for the entire match.
Though a more concise solution would be to use awk
, which supports Extended Regular Expressions and, by extension, alteration:
awk '{gsub(/\.(INFO|COM|NET)/, "& ")}1'
Upvotes: 0
Reputation: 15471
Try to escape pipes in pattern:
sed 's/\(INFO\|COM\|NET\)/& /g' file
Upvotes: 1