Computing.Net > Forums > Unix > delete text in sed

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

delete text in sed

Reply to Message Icon

Original Message
Name: suneethareddy3
Date: September 19, 2008 at 06:43:39 Pacific
Subject: delete text in sed
OS: Linux-fedora
CPU/Ram: 256
Manufacturer/Model: LG
Comment:

How to delete a character that is before the last character in all the lines in sed? plz...........do this favour for me

sun


Report Offensive Message For Removal


Response Number 1
Name: nails
Date: September 20, 2008 at 22:06:47 Pacific
Reply: (edit)

I couldn't figure out a regular expression to do this. However, using bash variable expansion, you can do a 2 step process: save the last char, and then remove the last two charcters and glue the saved character back on:


#!/bin/bash

while read var1
do
lc=${var1:((${#var1}-1))} # save the last char
var1=${var1%%??}${lc} # trim the last two chars and glue back the last char
echo "$var1"
done < datafile



Report Offensive Follow Up For Removal

Response Number 2
Name: ghostdog
Date: September 21, 2008 at 20:32:53 Pacific
Reply: (edit)


sed 's/.\(.\)$/\1/' file


Report Offensive Follow Up For Removal

Response Number 3
Name: suneethareddy3
Date: September 22, 2008 at 08:37:00 Pacific
Reply: (edit)

ThanQQQQQQQQQQQ

sun


Report Offensive Follow Up For Removal

Response Number 4
Name: nails
Date: September 22, 2008 at 09:52:03 Pacific
Reply: (edit)

Hey, Dog!

Good one!

Nails


Report Offensive Follow Up For Removal







Use following form to reply to current message:

Not Logged In!

You will not be able to post.

Register | Login
   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: delete text in sed

Comments:



  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 





Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 2 Days.
Discuss in The Lounge
Poll History




Data Recovery Software