delete lines form file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting delete lines form file
# 1  
Old 02-03-2011
delete lines form file

Hi

i am writing a cron job. in this script i need to delete some line which is match with some pattern.
following code i written for deletion
Code:
sed '1,'$Max_LIneNo' d' myfile.txt >tempfile.tmp
mv tempfile.tmp myfile.txt

this command is working fine but the problem is that after this deletion every time will give the rights to myfile.txt.

is there any other way to perform this deletion without help of any temp file

one more point i need to delete lines permanetly from file.

thanx in advance

Last edited by Franklin52; 02-03-2011 at 03:24 AM.. Reason: Please use code tags, thank you
# 2  
Old 02-03-2011
If you have GNU sed, then could use the below option which makes the change/writes to the original input file.
Code:
sed -i '1,'$Max_LIneNo' d' myfile.txt

# 3  
Old 02-03-2011
it is not working

showed error msg
Code:
sed :illegal option  --i is not valid


Last edited by Yogesh Sawant; 02-03-2011 at 06:04 AM.. Reason: added code tags
# 4  
Old 02-03-2011
Can't you just set a proper umask before executing the commands (man umask).
# 5  
Old 02-03-2011
sorry i did not get you.

now what should i do for unmask the command?
# 6  
Old 02-03-2011
umask, not unmask. What does
Code:
ls -l  myfile.txt

give, before and after?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Delete Some Lines from File

Hi, I have a txt document having a format like this: DATA1 | DATA2 | DATA3 | 23-JAN-20 23:41:34 DATA1 | DATA2 | DATA3 | 23-JAN-20 23:41:32 DATA1 | DATA2 | DATA3 | 23-JAN-20 23:41:30 ... DATA1 | DATA2 | DATA3 | 23-JAN-20 22:35:31 DATA1 | DATA2 | DATA3 | 23-JAN-20 22:30:34 DATA1 | DATA2 |... (1 Reply)
Discussion started by: gc_sw
1 Replies

2. Shell Programming and Scripting

Delete 40 lines after every 24 lines from a file

Hello, I have file of more than 10000 lines. I want to delete 40 lines after every 20 lines. e.g from a huge file, i want to delete line no from 34 - 74, then 94 - 134 etc and so on. Please let me know how i can do it. Best regards, (11 Replies)
Discussion started by: nehashine
11 Replies

3. Shell Programming and Scripting

Remove x lines form top and y lines form bottom using AWK?

How to remove x lines form top and y lines form bottom. This works, but like awk only cat file | head -n-y | awk 'NR>(x-1)' so remove last 3 lines and 5 firstcat file | head -n-3 | awk 'NR>4' (5 Replies)
Discussion started by: Jotne
5 Replies

4. UNIX for Advanced & Expert Users

In a huge file, Delete duplicate lines leaving unique lines

Hi All, I have a very huge file (4GB) which has duplicate lines. I want to delete duplicate lines leaving unique lines. Sort, uniq, awk '!x++' are not working as its running out of buffer space. I dont know if this works : I want to read each line of the File in a For Loop, and want to... (16 Replies)
Discussion started by: krishnix
16 Replies

5. UNIX for Dummies Questions & Answers

How get only required lines & delete the rest of the lines in file

Hiiii I have a file which contains huge data as a.dat: PDE 1990 1 9 18 51 28.90 24.7500 95.2800 118.0 6.1 0.0 BURMA event name: 010990D time shift: 7.3000 half duration: 5.0000 latitude: 24.4200 longitude: 94.9500 depth: 129.6000 Mrr: ... (7 Replies)
Discussion started by: reva
7 Replies

6. Shell Programming and Scripting

How to delete lines in a file that have duplicates or derive the lines that aper once

Input: a b b c d d I need: a c I know how to get this (the lines that have duplicates) : b d sort file | uniq -d But i need opossite of this. I have searched the forum and other places as well, but have found solution for everything except this variant of the problem. (3 Replies)
Discussion started by: necroman08
3 Replies

7. UNIX for Dummies Questions & Answers

Delete same lines out of file.

hello... I have a file with a list of filepaths in it, like so: delMe.txt (files to be deleted) ./root/index.php ./root/language/se/home.inc.php ./root/language/pl/home.inc.php Now here's what I'm trying to do. I want any lines in the above file (delMe.txt) to be deleted out of the... (3 Replies)
Discussion started by: jzacsh
3 Replies

8. Shell Programming and Scripting

How to extract visually blank lines form the file

Hi, Could some one help me to get rid of visually blank lines from a file using shell or awk or sed (on Solaris machine)? When I use grep grep -v ^$ inputfile >outputfile it removes some blank lines.. but it seems some tab plus space balnk lines remains. thaen I used "grep -v '^]*$' ... (1 Reply)
Discussion started by: hadsuresh
1 Replies

9. Shell Programming and Scripting

Random lines selection form a file.

>cat data.dat 0001 Robbert 0002 Nick 0003 Mark ....... 1000 Jarek (3 Replies)
Discussion started by: McLan
3 Replies

10. UNIX for Dummies Questions & Answers

delete lines in a file

I've got a file like this: Grid-ref= 443, 229 167 169 204 233 290 309 308 326 300 251 194 161 148 189 228 251 296 329 331 338 308 263 219 179 178 203 215 252 277 319 327 335 312 264 196 149 120 172 226 253 297 329 323 322 305 242 203 136 ... (20 Replies)
Discussion started by: su_in99
20 Replies
Login or Register to Ask a Question