×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

delete character in nth position

delete character in nth position

delete character in nth position

(OP)
Hi to all,

i have this kind of data:

60 , 70 , 90 , 27,345 , 10
30 , 40 , 100 , 38,900 , 12
41 , 23 , 98 , 21,200 , 09

I've wanted to remove the comma in 4th position to be able to come up with below output using perl:

60 , 70 , 90 , 27345 , 10
30 , 40 , 100 , 38900 , 12
41 , 23 , 98 , 21200 , 09

Hope someone could enlighten me on this. TIA.

RE: delete character in nth position

Hi

Must it be Perl ? For this particular case Sed has a special trick ( as far as I know ) not available in Perl :

CODE

sed 's/,//4' /input/file 

Feherke.
http://feherke.github.com/

RE: delete character in nth position

Hi

The above Sed code's closest Perl equivalent could be this :

CODE

perl -naF'\s*,\s*' -e 'splice@F,3,2,$F[3].$F[4];print join" , ",@F' /input/file 

But in case your problem can be rephrased as "remove the comma which is not surrounded by spaces", it can be reduced to :

CODE

perl -pe 's/(?<!\s),(?!\s)//' /input/file 

Feherke.
http://feherke.github.com/

RE: delete character in nth position

(OP)
hi Feherke,

Thanks once again. solution 1 and 2 really works . Great!!!

RE: delete character in nth position

Hi

Quote (Feherke)

The above Sed code's closest Perl equivalent could be this :

CODE

perl -naF'\s*,\s*' -e 'splice@F,3,2,$F[3].$F[4];print join" , ",@F' /input/file 
Actually that was wrong wording. The Sed code's equivalent whould be something like this :

CODE

perl -pe '$n=0;s/\s*,\s*/$n++==3?"":$&/ge' /input/file 

Feherke.
http://feherke.github.com/

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close