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


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Need to remove lines starting with an ID from all fine in a director
# 1  
Old 03-08-2018
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

Code:
(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;;;;;;;;;;;;;;;;;;;;;;;;;;

# 2  
Old 03-08-2018
Single command or single line command? Would
Code:
for FN in e*.dat; do grep -v '^8800[23]' $FN > TMP; mv TMP $FN; done

do?

Last edited by RudiC; 03-08-2018 at 07:03 PM..
This User Gave Thanks to RudiC For This Post:
# 3  
Old 03-08-2018
Test with
Code:
perl -ne 'print unless /^8800[23];/' extract_sales_007_423_A01.dat

Mass rewrite
Code:
perl -i.bak -ne 'print unless /^8800[23];/' *.dat

This User Gave Thanks to Aia For This Post:
# 4  
Old 03-08-2018
Quote:
Originally Posted by RudiC
Single command or single line command? Would
Code:
for FN in e*.dat; do grep -v '^8800[23]' $FN > TMP; mv TMP $FN; done

do?
Worked perfect... Thanks a lot

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

Quote:
Originally Posted by Aia
Test with
Code:
perl -ne 'print unless /^8800[23];/' extract_sales_007_423_A01.dat

Mass rewrite
Code:
perl -i.bak -ne 'print unless /^8800[23];/' *.dat

Tried both and worked. thanks a lot
# 5  
Old 03-09-2018
Late to the party again!
Code:
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to grep a line not starting with # from a file (there are two lines starting with # and normal)?

e.g. File name: File.txt cat File.txt Result: #INBOUND_QUEUE=FAQ1 INBOUND_QUEUE=FAQ2 I want to get the value for one which is not commented out. Thanks, (3 Replies)
Discussion started by: Tanu
3 Replies

2. UNIX for Advanced & Expert Users

Problem piping find output to awk, 1st line filename is truncated, other lines are fine.

Today I needed to take a look through a load of large backup files, so I wrote the following line to find them, order them by size, and print the file sizes in GB along with the filename. What happened was odd, the output was all as expected except for the first output line which had the filename... (4 Replies)
Discussion started by: gencon
4 Replies

3. Shell Programming and Scripting

Remove all lines except lines starting with [

Hello, I am trying to remove all the lines in file except lines starting with [ How can i accomplish this? Thank you very much in advance. (4 Replies)
Discussion started by: maxo
4 Replies

4. Shell Programming and Scripting

Concatenate lines between lines starting with a specific pattern

Hi, I have a file such as: --- >contig00001 length=35524 numreads=2944 gACGCCGCGCGCCGCGGCCAGGGCTGGCCCA CAGGCCGCGCGGCGTCGGCTGGCTGAG >contig00002 length=4242 numreads=43423 ATGCCGAAGGTCCGCCTGGGGCTGG CGCCGGGAGCATGTAGCG --- I would like to concatenate the lines not starting with ">"... (9 Replies)
Discussion started by: s052866
9 Replies

5. Shell Programming and Scripting

remove lines starting with

Hi I have an input file... /* ----------------- AGYDLY_Box ----------------- */ insert_job: AGYDLY_Box job_type: b owner: spdrdev permission: gx,wx date_conditions: 1 days_of_week: mo,tu,we,th,fr exclude_calendar: mtg_holidays start_times: "1:00" description: "Process Daily New pools... (2 Replies)
Discussion started by: ramky79
2 Replies

6. Shell Programming and Scripting

Remove field starting with * and #

Hi i have file with data: abc,*xyz,#abc 123,#123,1234 *123,#123,abc So i want to remove only fields starting with * and # and i want output as: abc,, 123,,1234 ,,abc Please suggest something Thanks Sumit (3 Replies)
Discussion started by: sumit207
3 Replies

7. Shell Programming and Scripting

shell script to remove all lines from a file before a line starting with pattern

hi,, i hav a file with many lines.i need to remove all lines before a line begginning with a specific pattern from the file because these lines are not required. Can u help me out with either a perl script or shell script example:- if file initially contains lines: a b c d .1.2 d e f... (2 Replies)
Discussion started by: raksha.s
2 Replies

8. UNIX for Dummies Questions & Answers

remove lines in text starting with . (period)

how can i remove lines from a text file starting with . (a period) (11 Replies)
Discussion started by: Movomito
11 Replies

9. Shell Programming and Scripting

How to remove files starting with -

Hi, Can anyone suggest me how to remove the file whose name starts with "-". Say i have a file by name -out. I want to remove this. I tried escaping -, but didnt work. I work on AIX 5.3 machine. Thanks in advance. Suman (5 Replies)
Discussion started by: suman_jakkula
5 Replies

10. UNIX for Advanced & Expert Users

How To Remove files starting with -

In Unix/Linux when u create a file starting with a - e.g.-file then when u try to remove or rename it, it is not possible. e.g. rm -file . when we give this command rm assumes to be its option rather than its argument. Same is the case when this filename is given as an argument to mv or cat and... (2 Replies)
Discussion started by: rahulrathod
2 Replies
Login or Register to Ask a Question