Deletion of lines in a text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deletion of lines in a text file
# 1  
Old 07-02-2008
Deletion of lines in a text file

Hi Everyone,
Please help me with this. I have gone through many posts here but couldn't find what I wanted.

I have a file with 79000+ lines and I want to delete lines in a pattern.

I want to delete every 141st line in the file, starting from line 2000 till 50000.

Please help guys.

Regards,
Abhi
# 2  
Old 07-02-2008
Try this :

Code:
sed -n '2000,50000p'  file | awk '{ if ((NR%141) != 0) print $0; }'

# 3  
Old 07-02-2008
Thanks Dennis

Half of my problem is solved now....only thing left is that, what should i do to get the lines before and after the starting and ending points.

Anyways thanks very much for this help.

Regards,
Abhi
# 4  
Old 07-02-2008
Try like this:

Code:
awk '{ if ((NR>=2000) && (NR<=50000)) { if ((NR%141) != 0) print $0; } else print;}' filename

# 5  
Old 07-02-2008
Problems solved

Thanks Dennis.

That helped !!!

U r great,,....
# 6  
Old 07-02-2008
One more thing....

I was trying to remove the 141st line after the start point (line 171) ....
i.e. (171 + 141)st line
so I tried the script
awk '{ if ((NR>=2000) && (NR<=50000)) { if ((NR+141) != 0) print $0; } else print;}' filename

But this is not working and instead printing everything intact.

Please can someone help.....

Dennis... be a savior again

Regards,
Abhi
# 7  
Old 07-02-2008
Something like this?

Code:
awk 'NR>=2000 && NR<=50000 && NR%141==30{next}1' file

Regards

Last edited by Franklin52; 07-02-2008 at 08:53 AM.. Reason: typo, missed a & in awk statement
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. UNIX for Dummies Questions & Answers

Deletion of list of user based on a text file In LDAP UNIX server

Dear All, It would be really nice, if you could help me to write a script for deletion of list of user( more than 15000 users) stored in a file and sorted by email address( i need deletion of only a particular type of mail address). Is the any script to write and take the file as input and... (3 Replies)
Discussion started by: Chand
3 Replies

3. Shell Programming and Scripting

Read n lines from a text files getting n from within the text file

I dont even have a sample script cause I dont know where to start from. My data lookes like this > sat#16 #data: 15 site:UNZA baseline: 205.9151 0.008 -165.2465 35.8109 40.6685 21.9148 121.1446 26.4629 -18.4976 33.8722 0.017 -165.2243 48.2201 40.6908 ... (8 Replies)
Discussion started by: malandisa
8 Replies

4. Shell Programming and Scripting

Taking the averages of columns with deletion of some lines

Hi, I am in stage of post processing some of my results. I wanted to plot the data against the three axis x,y,z. The data file is quite complicated and i have to take the average of x, y,z over different steps of my test. A typical file look like below: Time taken:4s No.of series : 3... (6 Replies)
Discussion started by: begin_shell
6 Replies

5. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

6. Shell Programming and Scripting

Pattern Matching and text deletion using VI

Can someone please assist me, I'm trying to get vi to remove all the occurences of the text in a file i.e. "DEVICE=/dev/mt??". The "??" represents a number variable. Is there a globel search and delete command that I can use? Thank You in Advance. (3 Replies)
Discussion started by: roadrunner
3 Replies

7. Shell Programming and Scripting

Comparison and deletion of lines between two files

Hi i need an help. I have two files list1 and list2, both contains the server names i want to delete the servers in list2 which were also found in list1. for an eg list2 list1 oradg1 oradg4 oradg2 oradg2 oradg3 ... (5 Replies)
Discussion started by: sudharson
5 Replies

8. Shell Programming and Scripting

[bash help]Adding multiple lines of text into a specific spot into a text file

I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it. For example, Here is a portion of a zone file. IN NS ns1.domain.tld. IN NS ns2.domain.tld. IN ... (2 Replies)
Discussion started by: cdn_humbucker
2 Replies

9. Shell Programming and Scripting

Operations on a file with Deletion , Modification and Insertion of lines

Hi All , Given a file , I need to delete , modify and insert lines matching certain patterns in that file using shell scripting. e.g. If a file FILE1 has following content : CUST.ABC.DEF = CUST.ABC.DEF * CUST.ABC.DEF PRINTF(CUST.ABC.DEF) CUST.ABC.DEF = mid(CUST.ABC.DEF,10.34)... (5 Replies)
Discussion started by: swapnil.nawale
5 Replies

10. UNIX for Dummies Questions & Answers

deletion of all lines ends with :

I have below file say temp1 BSCAJM1:HWJA10C BSCAJM1: BSCALW1: BSCALW1:GVND01B BSCALW1: BSCALW1: BSCBKNR:IJNMKTA BSCBKNR: BSCJOD1: BSCJOD1:JOD121B i want to delete all the lines ending with : and have below output BSCAJM1:HWJA10C BSCALW1:GVND01B BSCBKNR:IJNMKTA... (8 Replies)
Discussion started by: lalchand
8 Replies
Login or Register to Ask a Question