Need to remove lines starting with an ID from all fine in a director

Hi All,

I have almost 200 files in a directory I want to remove all lines in each file that is starting with 88002 and 88003 . I tried with grep -v and if I plan to do that I need to for all the files individually and it is 200+ files. Any way I can do at single command

(cvg13:tppr:/extract/423>) ls -lrt
-rw-r--r-- 1 tppr m02    42952 Mar  7 00:37extract_sales_007_423_A01.dat
-rw-r--r-- 1 tppr m02    38522 Mar  7 00:37extract_sales_006_423_A01.dat
-rw-r--r-- 1 tppr m02   115716 Mar  7 00:37extract_sales_005_423_A01.dat
-rw-r--r-- 1 tppr m02    95383 Mar  7 00:37extract_sales_004_423_A01.dat
-rw-r--r-- 1 tppr m02    28311 Mar  7 00:37extract_sales_003_423_A01.dat
-rw-r--r-- 1 tppr m02    73816 Mar  7 00:37extract_sales_002_423_A01.dat
-rw-r--r-- 1 tppr m02    78606 Mar  7 00:37extract_sales_001_423_A01.dat

(cvg13:tppr:/extract/423>)  grep 88002  extract_sales_007_423_A01.dat
88002;15280;423;;;;;;;1469807.47;;;;;;;;;;;;;;;;;;;;;;;;;;
88002;15281;423;;;;;;;97841.44;;;;;;;;;;;;;;;;;;;;;;;;;;
88002;15282;423;;;;;;;12892033.14;;;;;;;;;;;;;;;;;;;;;;;;;;
88002;15283;423;;;;;;;20675576.65;;;;;;;;;;;;;;;;;;;;;;;;;;
88002;15284;423;;;;;;;1245817.84;;;;;;;;;;;;;;;;;;;;;;;;;;
88002;15285;423;;;;;;;8242412.50;;;;;;;;;;;;;;;;;;;;;;;;;;
88002;15286;423;;;;;;;1793957.55;;;;;;;;;;;;;;;;;;;;;;;;;;
88002;15287;423;;;;;;;3952298.48;;;;;;;;;;;;;;;;;;;;;;;;;;

Single command or single line command? Would

for FN in e*.dat; do grep -v '^8800[23]' $FN > TMP; mv TMP $FN; done

do?

1 Like

Test with

perl -ne 'print unless /^8800[23];/' extract_sales_007_423_A01.dat

Mass rewrite

perl -i.bak -ne 'print unless /^8800[23];/' *.dat
1 Like

Worked perfect... Thanks a lot

---------- Post updated at 05:42 AM ---------- Previous update was at 05:40 AM ----------

Tried both and worked. thanks a lot

Late to the party again!

sed -i.bak '/^8800[23]/d' *.txt
sed -i       '/^8800[23]/d' *.txt # no back-up file
 

This uses GNU sed with the -i (inline) option. Not all seds will recognise this.

Andrew