If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
encounter problem again -_-b
i want to insert some character into specific position in a line, for example
insert a char after the 4th char, or insert a char in front of the 2nd field.etc.........
how can these be done then......
thanks for ur attention.......
I have a bunch of codes (like 80), every code has several subroutines. The task I was posed is to add C preprocessing to each subroutine (add #ifdef before each subroutine). I think this can be done using awk script. Could anybody help me on this? Please send email to julytli01@yahoo.com, thanks a lot!
Quote:
Originally posted by aigles
Code:
Line="Txt: for test"
#
# Insert string after the 4th char
#
echo "$Line" | \
sed 's/^\(.\{4\}\)/\1(sed after 4th char)/'
echo "$Line" | \
awk '{print substr($0,1,4) "(awk after 4th char)" substr($0,5)}'
#
# Insert string before field 2
#
echo "$Line" | \
awk '{$2 = "(awk before field2)" $2;print $0}'