online.0227
online.0227

Reputation: 648

Reverse output in sed

test.sed:

#!/bin/sed -Ef

/^(1|\+1)\(([0-9]{3})\)(555)-([0-9]{4})/d
/^\(([0-9]{3})\)(555)-([0-9]{4})/d

file.txt:

(123)456-7890
1(123)456-7890
+1(123)456-7890

(123)555-7890
1(123)555-7890
+1(123)555-7890

(416)736-5053
1(416)736-2100
+1(416)736-2100

Current Output:

(123)456-7890
1(123)456-7890
+1(123)456-7890


(416)736-5053
1(416)736-2100
+1(416)736-2100

Expected Output:

(123)555-7890
1(123)555-7890
+1(123)555-7890

Hello. I want to have Expected Output as above, which is just picking up 3 sentences which are not picked up in current output.

Is there a way to do that by having -Ef flag? you can add more flag, but I can't delete these flag.

I tried like following, which didn't work:

/^(1|\+1)\(([0-9]{3})\)(555)-([0-9]{4})/p
/^\(([0-9]{3})\)(555)-([0-9]{4})/p

Upvotes: 1

Views: 60

Answers (1)

RomanPerekhrest
RomanPerekhrest

Reputation: 92854

Use the following approach:

test.sed:

#!/bin/sed -Ef
/\([0-9]{3}\)555-[0-9]{4}/!d 

Command:

sed -Ef test.sed file.txt

The output:

(123)555-7890
1(123)555-7890
+1(123)555-7890

Upvotes: 1

Related Questions