May 4, 2007 #1 ogniemi Technical User Joined Nov 7, 2003 Messages 1,041 Location PL in sed and awk? thx!
May 4, 2007 #2 feherke Programmer Joined Aug 5, 2002 Messages 9,541 Location RO Hi Assuming the character to be added is "x" : Code: awk '{$0=substr($0,1,length($0)-1)"x"substr($0,length($0))}1' /input/file [gray]# or ( gawk only )[/gray] awk '{print gensub(/(.)$/,"x\\1","")}' /input/file [gray]# or[/gray] sed 's/\(.\)$/x\1/' /input/file Feherke. http://rootshell.be/~feherke/ Upvote 0 Downvote
Hi Assuming the character to be added is "x" : Code: awk '{$0=substr($0,1,length($0)-1)"x"substr($0,length($0))}1' /input/file [gray]# or ( gawk only )[/gray] awk '{print gensub(/(.)$/,"x\\1","")}' /input/file [gray]# or[/gray] sed 's/\(.\)$/x\1/' /input/file Feherke. http://rootshell.be/~feherke/
May 4, 2007 1 #3 p5wizard IS-IT--Management Joined Apr 18, 2005 Messages 3,165 Location BE To add an X before the last char of every line: Code: sed 's/.$/X&/' </path/to/input >/path/to/output HTH, p5wizard Upvote 0 Downvote
To add an X before the last char of every line: Code: sed 's/.$/X&/' </path/to/input >/path/to/output HTH, p5wizard
May 4, 2007 #4 feherke Programmer Joined Aug 5, 2002 Messages 9,541 Location RO Hi Of course, you are right ! That [tt]&[/tt] works in regular [tt]awk[/tt] implementations too, so can be used in [tt]sub()[/tt]. Thank you, p5wizard. Feherke. http://rootshell.be/~feherke/ Upvote 0 Downvote
Hi Of course, you are right ! That [tt]&[/tt] works in regular [tt]awk[/tt] implementations too, so can be used in [tt]sub()[/tt]. Thank you, p5wizard. Feherke. http://rootshell.be/~feherke/