Skip to main content
replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
Source Link

I have the following cases:

 [email protected] [email protected] [email protected] 

I'm trying to convert these to

 [email protected] [email protected] [email protected] 

So it should remove everything from the first '_' (including it) to the @ (not including that).

I have something, but it doesn't really work correctly:

Based on this thread: Cut based on Two Delimiters at one go, and this U&L Q&A: Splitting string by the first occurrence of a delimiterSplitting string by the first occurrence of a delimiter.

sed 's/^.*_\([^ ]*\) .*\@\([^$]*\)$/\1 \2/' infile 

But no luck. Anyone want to take a chime at it?

I have the following cases:

 [email protected] [email protected] [email protected] 

I'm trying to convert these to

 [email protected] [email protected] [email protected] 

So it should remove everything from the first '_' (including it) to the @ (not including that).

I have something, but it doesn't really work correctly:

Based on this thread: Cut based on Two Delimiters at one go, and this U&L Q&A: Splitting string by the first occurrence of a delimiter.

sed 's/^.*_\([^ ]*\) .*\@\([^$]*\)$/\1 \2/' infile 

But no luck. Anyone want to take a chime at it?

I have the following cases:

 [email protected] [email protected] [email protected] 

I'm trying to convert these to

 [email protected] [email protected] [email protected] 

So it should remove everything from the first '_' (including it) to the @ (not including that).

I have something, but it doesn't really work correctly:

Based on this thread: Cut based on Two Delimiters at one go, and this U&L Q&A: Splitting string by the first occurrence of a delimiter.

sed 's/^.*_\([^ ]*\) .*\@\([^$]*\)$/\1 \2/' infile 

But no luck. Anyone want to take a chime at it?

added 155 characters in body
Source Link
slm
  • 380k
  • 127
  • 793
  • 897

I have the following cases:

 [email protected] [email protected] [email protected] 

I'm trying to convert these to

 [email protected] [email protected] [email protected] 

So it should remove everything from the first '_' (including it) to the @ (not including that).

I have something, but it doesn't really work correctly:

Based on this thread: http://www.unix.com/shell-programming-scripting/34542-cut-based-two-delimiters-one-go.htmlCut based on Two Delimiters at one go, and this U&L Q&A: Splitting string by the first occurrence of a delimiter.

sed 's/^.*_\([^ ]*\) .*\@\([^$]*\)$/\1 \2/' infile 

But no luck, anyone. Anyone want to take a chime at it?

I have the following cases:

 [email protected] [email protected] [email protected] 

I'm trying to convert these to

 [email protected] [email protected] [email protected] 

So it should remove everything from the first '_' (including it) to the @ (not including that)

I have something but it doesn't really work correctly:

Based on http://www.unix.com/shell-programming-scripting/34542-cut-based-two-delimiters-one-go.html and Splitting string by the first occurrence of a delimiter

sed 's/^.*_\([^ ]*\) .*\@\([^$]*\)$/\1 \2/' infile 

But no luck, anyone want to take a chime at it?

I have the following cases:

 [email protected] [email protected] [email protected] 

I'm trying to convert these to

 [email protected] [email protected] [email protected] 

So it should remove everything from the first '_' (including it) to the @ (not including that).

I have something, but it doesn't really work correctly:

Based on this thread: Cut based on Two Delimiters at one go, and this U&L Q&A: Splitting string by the first occurrence of a delimiter.

sed 's/^.*_\([^ ]*\) .*\@\([^$]*\)$/\1 \2/' infile 

But no luck. Anyone want to take a chime at it?

Source Link
Sten Kin
  • 391
  • 2
  • 4
  • 9

Using cut/awk/sed with two different delimiters

I have the following cases:

 [email protected] [email protected] [email protected] 

I'm trying to convert these to

 [email protected] [email protected] [email protected] 

So it should remove everything from the first '_' (including it) to the @ (not including that)

I have something but it doesn't really work correctly:

Based on http://www.unix.com/shell-programming-scripting/34542-cut-based-two-delimiters-one-go.html and Splitting string by the first occurrence of a delimiter

sed 's/^.*_\([^ ]*\) .*\@\([^$]*\)$/\1 \2/' infile 

But no luck, anyone want to take a chime at it?