Re: Deleting a line from a file

2014-05-15 Thread Bernd Petrovitsch
On Mit, 2014-05-14 at 21:27 +0530, Saket Sinha wrote: [...] I wanted to isolate the problem hence did not give the full context. Actually I have written a file-system utility which mounts my filesystem on a specific path and update it in /etc/fstab. When I umount it, I delete the path from the

Re: Deleting a line from a file

2014-05-15 Thread Bernd Petrovitsch
On Mit, 2014-05-14 at 11:18 -0400, valdis.kletni...@vt.edu wrote: On Wed, 14 May 2014 16:34:20 +0200, Bernd Petrovitsch said: sed -i 's#^/opt/new1.*$#d' file_entries.txt You don't even need the leading 's'. Just /pattern/d is sufficient. Ooops, yes, thanks. So sed -i

Re: Deleting a line from a file

2014-05-15 Thread Valdis . Kletnieks
On Thu, 15 May 2014 09:55:52 +0200, Bernd Petrovitsch said: sed -i '/\/opt\/new1/d' file_entries.txt should do it. Just for the match, we do not need, the tailing .*$ (because it matches always). Actually, you want to use /^\/opt\/new1[ \t]/d because otherwise it will also delete lines that

Deleting a line from a file

2014-05-14 Thread Saket Sinha
Hi, I have a file that has entries for different absolute path on separate lines. eg: /opt/new1 /opt/new2 I need to delete an entry from this file for a given path, for which I am using sed. sed -i 's#^/opt/new1.*$##g' file_entries.txt However this is leaving blank line in between, which I

Re: Deleting a line from a file

2014-05-14 Thread Bernd Petrovitsch
Hi! The original mail is off-topic as it has nothing to do wotj the Linux kernel development as such, but: On Mit, 2014-05-14 at 19:58 +0530, Saket Sinha wrote: [...] I have a file that has entries for different absolute path on separate lines. eg: /opt/new1 /opt/new2 I need to delete

Re: Deleting a line from a file

2014-05-14 Thread Valdis . Kletnieks
On Wed, 14 May 2014 16:34:20 +0200, Bernd Petrovitsch said: sed -i 's#^/opt/new1.*$#d' file_entries.txt You don't even need the leading 's'. Just /pattern/d is sufficient. (And you can even do stuff like /pat1/,/pat2/s/old/new/ which will change 'old' to 'new', but only from a line

Re: Deleting a line from a file

2014-05-14 Thread Saket Sinha
Please find my response inline- On Wed, May 14, 2014 at 8:04 PM, Bernd Petrovitsch be...@petrovitsch.priv.at wrote: Hi! The original mail is off-topic as it has nothing to do wotj the Linux kernel development as such, but: I wanted to isolate the problem hence did not give the full context.

Re: Deleting a line from a file

2014-05-14 Thread Valdis . Kletnieks
On Wed, 14 May 2014 21:27:06 +0530, Saket Sinha said: char newFileName[PATH_MAX]; tabFileNew = setmntent(newFileName, w); And what is the new file name? You have random trash on the stack here. (Note that this is C 101 - if you can't debug this on your own, you probably shouldn't be

Re: Deleting a line from a file

2014-05-14 Thread Saket Sinha
Please find response inline. On Wed, May 14, 2014 at 9:44 PM, valdis.kletni...@vt.edu wrote: On Wed, 14 May 2014 21:27:06 +0530, Saket Sinha said: char newFileName[PATH_MAX]; tabFileNew = setmntent(newFileName, w); And what is the new file name? You have random trash on the

Re: Deleting a line from a file

2014-05-14 Thread Valdis . Kletnieks
On Wed, 14 May 2014 22:13:51 +0530, Saket Sinha said: I am sending /etc/fstab in fileName to this function and the path to be deleted in fullPath OK. char newFileName[PATH_MAX]; This lives on your function call stack. As such, it contains whatever was in that memory until you change it.