| 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
|
Original Message
|
Name: suneethareddy3
Date: September 19, 2008 at 06:43:39 Pacific
Subject: delete text in sedOS: Linux-fedoraCPU/Ram: 256Manufacturer/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/bashwhile 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
|
Use following form to reply to current message: