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
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
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
Summary: Hi Bill, this is easy in sed just sed -n '3p' fileA But it didn't realy delete the rows in fileA just print's the 3 row. So a redirection of the out put should be used e.g. sed -n '3p' fileA > fileB t...
Summary: Hi Folks, In sed and/or awk, how would I formulate an if/else logic to skip a command if a specific text already exist in a file? I am getting multiple entries in a text file when the script is execu...
Summary: Hi I am using sed in a shell script. I am having problems in using parameters in sed for search and replace. TEST=`grep "'/" source | head -1` sed s/$TEST/string1/g source.txt > target.txt This doesn...