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

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 text in sed

Reply to Message Icon

Name: suneethareddy3
Date: September 19, 2008 at 06:43:39 Pacific
OS: Linux-fedora
CPU/Ram: 256
Product: 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



Sponsored Link
Ads by Google

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

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



0

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


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


0

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

ThanQQQQQQQQQQQ

sun


0

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

Hey, Dog!

Good one!

Nails


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: delete text in sed

deleting rows in a file www.computing.net/answers/unix/deleting-rows-in-a-file/3676.html

How to use if/else logic in sed/awk www.computing.net/answers/unix/how-to-use-ifelse-logic-in-sedawk/6207.html

parameters in sed www.computing.net/answers/unix/parameters-in-sed/6942.html