Computing.Net > Forums > Unix > Delete a word from a file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Delete a word from a file

Reply to Message Icon

Name: poornimajayan
Date: May 4, 2009 at 10:18:16 Pacific
OS: KSH
Subcategory: General
Comment:

Hi,
I have a file which is as follows and I want to delete all occurrences of the /jsn/pjs/ .

270 644 /jsn/pjs/1.txt
79 17 /jsn/pjs/2.txt


I tried using as sed 's//jsn/pjs/,//g' xyz.txt

But it does not work.Can soemone please help where I am wrong?I am using KSH.

Thanks,
Poornima



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: May 4, 2009 at 10:31:11 Pacific
Reply:

You have to escape the default delimiter, /, that sed uses:

#!/bin/ksh

sed 's/\/jsn\/pjs\///g' xyz.txt

# or you can change the delimiter:

sed 's&/jsn/pjs/&&g' xyz.txt


0

Response Number 2
Name: poornimajayan
Date: May 4, 2009 at 11:31:35 Pacific
Reply:

Thanks a lot Nails. I used your second option.
Since replace was not occurring in the original file(xyz.txt), I put the output to a separate file b.txt and deleted the xyz.txt.
Thanks
Poornima


0

Response Number 3
Name: ghostdog
Date: May 5, 2009 at 02:18:44 Pacific
Reply:

another way without too much meddling with slashes

# awk 'BEGIN{FS="/jsn/pjs/"}{$1=$1}1' file
270 644  1.txt
79 17  2.txt


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


how to fetch the fileds f... rsh (remsh) -l


Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Delete a word from a file

How do you delete SCO UNIX from a harddisk www.computing.net/answers/unix/how-do-you-delete-sco-unix-from-a-harddisk/1253.html

Script to delete lines from a file www.computing.net/answers/unix/script-to-delete-lines-from-a-file/7408.html

Delete last character in a file www.computing.net/answers/unix/delete-last-character-in-a-file/5310.html