Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I need to insert today's date (dd-mm-yyyy) at the end of each and every line in a text file. I nees #!/bin/sh.
My file as follows.
-------------------------one , three , ten , five
twelve , ten , five , one
...............................
...............................
one , two , nine , eightOutput file should be:
one , three , ten , five , 25-08-2006
twelve , ten , five , one, 25-08-2006
...............................
...............................
one , two , nine , eight, 25-08-2006
Thanks

#!/bin/ksh
var=$(date '+%d-%m-%Y')
# using the shell
while read line
do
printf "%s,%s\n" "$line" "$var"
done < text.file# using awk
awk ' { printf("%s,%s\n", $0, v1) } ' v1="$var" text.file
# using sed
sed "s/$/,$var/" text.file

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |