sed basic doubt

Hi ,

what is the equivalent of below awk in sed.

awk '$1=="ABC"&&$2=="XYZ" {print $0}' infile

Thanks,
Shruthi

Basically

sed -n '/^ABC  *XYZ/p' 

but there are nuances with tabs and starting spaces (and/or tabs).

With GNU sed this is the same:

sed -r -n '/^[ \t]*ABC[ \t]+XYZ/p' infile

Hi Yazu,

I am trying to apply a sed logic using the below code only if my first column has ABC and second column as XYZ,but the below code is not giving the required output.

sed -r -n  '/^[ \t]*ABC[ \t]+XYZ/ { s/98850|97415|24874//g }'  Duplicate_phone_numbers.csv  > generated.csv

can you please tell me where I am doing it wrong.

T&R,Shruthi

Please, give an example of the input.

It's possible you just don't put ";p" after "g" (or maybe you need remove "-n") but I believe there are maybe another problems.

Hi yazu,

Below is my source data

AIRTEL,POSTPAID,98850,9885714478,9885814478,9665871143
AIRTEL,PREPAID,97415,9885714478,9885814478,9665871143
AIRTEL,POSTPAID,24874,9885714478,9885814478,9665871143

If my first column is AIRTEL and second column is POSTPAID then I am removing the 98850 and 24874 from the 3rd column data

so my out will be as below

Target Data
AIRTEL,POSTPAID,9885714478,9885814478,9665871143
AIRTEL,PREPAID,97415,9885714478,9885814478,9665871143
AIRTEL,POSTPAID,9885714478,9885814478,9665871143

T&R,Shruthi

In every line which begins with "AIRTEL,POSTPAID" this code substitutes the first substring which matches the next pattern: "comma" "number or another number" "comma" by one "comma":

sed -r '/^AIRTEL,POSTPAID/ s/,(98850|24874),/,/' 

GNU sed, extended regular expressions.

Additionally, after XYZ, one would need to test for blanks or end of line.

(Yes, I am aware that what follows is a nitpick. ;))

The standard doesn't specify space and tabs but blank characters (which as far as I know is always space and tab regardless of locale, but who knows), so it might be better to use the [:blank:] character class instead of a bracket expression with hardcodes a space and tab.

Regards,
Alister