How to remove certain lines in multiple txt files?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to remove certain lines in multiple txt files?
# 1  
Old 11-13-2008
Question How to remove certain lines in multiple txt files?

Hi ,

I have this type of files:-

BGH.28OCT2008.00000001.433155.001
BGH.28OCT2008.00000002.1552361.001
BGH.28OCT2008.00000003.1438355.001
BGH.28OCT2008.00000004.1562602.001

Inside them contains the below:

5Discounts
6P150 - Max Total Usage RM150|-221.00
P150 EPP - Talktime RM150 x 24|-169.35
7-390.35
90.00
812.71
3ITEMISED|YES
4DOMESTIC
5Calls
Calls
Calls
Calls
Calls
Calls
Calls
Calls
Calls
.
.
.
5Discounts
6P150 - Max Total Usage RM150|-221.00
P150 EPP - Talktime RM150 x 24|-169.35
7-390.35
90.00
812.71
3ITEMISED|YES
4DOMESTIC
5Calls
Calls
Calls
Calls
Calls
Calls
Calls
Calls
Calls
.
.
.

How do I get those line in green deleted as i do not know when is the last 'calls' line?
And how do I loop to remove those lines in all the txt files?

Anyone can help?
# 2  
Old 11-13-2008
using sed:
Code:
sed -i -e '/Calls/d' BGH.28OCT2008.*

# 3  
Old 11-13-2008
Thanks Yogesh for your prompt reply.

What about the data is as below:
And everytime the date will be different from certain txt files.

521/10/2008|20:52:41|Central-02|016|00:03:23|OFFP|GTele|01|0.53
21/10/2008|20:56:30|Central-01|016|00:00:18|OFFP|GTele|01|0.08
21/10/2008|20:57:02|North-01|016|00:00:12|OFFP|GTele|02|0.08
21/10/2008|20:58:02|North-01|016|00:00:04|OFFP|GTele|02|0.08
# 4  
Old 11-13-2008
What do you want deleted from these lines?
# 5  
Old 11-15-2008
I want to delete the below in green.
There is no line limitation.
And I do not know until which line i have to delete.
How to i detect the last patten of the below data and delete it?

5Discounts
6P150 - Max Total Usage RM150|-221.00
P150 EPP - Talktime RM150 x 24|-169.35
7-390.35
90.00
812.71
3ITEMISED|YES
4DOMESTIC
521/10/2008|20:56:30|Central-01|016|00:00:18|OFFP|GTele|01|0.08
21/10/2008|20:57:02|North-01|016|00:00:12|OFFP|GTele|02|0.08
21/10/2008|20:58:02|North-01|016|00:00:04|OFFP|GTele|02|0.08
.
.
# 6  
Old 11-15-2008
Let me get this straight. You want to delete the lines in green. But you don't know which lines these are until you come across "the last pattern"? And then you want to delete the lines above it? So what is special about the line that tells you that you need to delete it and the other lines?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

To Remove multiple new lines

Hi , I have file which consists of multiple new lines. I need to identify the new line in every row of the file and remove it. It is having record delimiter as "|" and final delimiter of the line is "end" Can anyone from the forum suggest me how to remove the news lines from entire file? example... (11 Replies)
Discussion started by: etldeveloper
11 Replies

2. UNIX for Dummies Questions & Answers

Need help combining txt files w/ multiple lines into csv single cell - also need data merge

:confused:Hello -- i just joined the forums. I am a complete noob -- only about 1 week into learning how to program anything... and starting with linux. I am working in Linux terminal. I have a folder with a bunch of txt files. Each file has several lines of html code. I want to combine... (2 Replies)
Discussion started by: jetsetter
2 Replies

3. UNIX for Dummies Questions & Answers

redirecting arguments in a script to multiple lines in a .txt file

Ok hope my vocab is right here, i'm trying to write multiple sets of arguments to another file for example: I have a script that accepts four arguments and sends them to a another file $write.sh it then out in so the file receiver.txt would contain this: it then out in what... (2 Replies)
Discussion started by: austing5
2 Replies

4. UNIX for Advanced & Expert Users

How to remove degree symbol from the TXT files?

I have TXT files to process but they contain the degree symbols in them due to which the processing program fails on these files. I want a unix command that will remove the degree symbols from these files. I tried using the sed command: sed 's///g' filename but it did not work. This issue... (14 Replies)
Discussion started by: khedu
14 Replies

5. Shell Programming and Scripting

merging two .txt files by alternating x lines from file 1 and y lines from file2

Hi everyone, I have two files (A and B) and want to combine them to one by always taking 10 rows from file A and subsequently 6 lines from file B. This process shall be repeated 40 times (file A = 400 lines; file B = 240 lines). Does anybody have an idea how to do that using perl, awk or sed?... (6 Replies)
Discussion started by: ink_LE
6 Replies

6. Shell Programming and Scripting

replace a string with contents of a txt file containing multiple lines of strings

Hello everyone, ive been trying to replace a string "kw01" in an xml file with the contents of a txt file having multiple lines. im a unix newbie and all the sed combinations i tried resulted to being garbled. Below is the contents of the txt file: RAISEDATTIME --------------------... (13 Replies)
Discussion started by: 4dirk1
13 Replies

7. UNIX for Dummies Questions & Answers

How to remove characters from multiple .txt files

Friends, I want to remove charecters from multiple .txt files. Foe example : In this .txt files there are many "ctrl m" present in last of each line in one .txt file. I want to remove "ctrl m" from each line from all .txt files. Need your help regarding this. (4 Replies)
Discussion started by: meetsubhas
4 Replies

8. Shell Programming and Scripting

Number of *.txt files which have over n lines?

Can you help me please? I know that wc -l *.txt gives you the number of lines in each file. But how can i count the files that have over n lines? (4 Replies)
Discussion started by: dark_knight
4 Replies

9. UNIX for Dummies Questions & Answers

Compare and Remove duplicate lines from txt

Hello, I am a total linux newbie and I can't seem to find a solution to this little problem. I have two text files with a huge list of URLS. Let's call them file1.txt and file2.txt What I want to do is grab an URL from file2.txt, search file1.txt for the URL and if found, delete it from... (11 Replies)
Discussion started by: rmarcano
11 Replies

10. Shell Programming and Scripting

need help--script to filter specific lines from multiple txt files

Hi folks, - I have 800 txt files - those files are cisco router configs router1.txt router2.txt ... router800.txt I want to accomplish the following: - I want to have a seperate file with all the filenames that I want to process - I want a script that goes trough all those... (7 Replies)
Discussion started by: I-1
7 Replies
Login or Register to Ask a Question