Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to add one character before the last one in each line... 1

Status
Not open for further replies.

ogniemi

Technical User
Nov 7, 2003
1,041
PL
in sed and awk?


thx!
 
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.
 
To add an X before the last char of every line:

Code:
sed 's/.$/X&/' </path/to/input >/path/to/output


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top