Add a column to a file.
Hi i have file which looks like below.
I want add 5th column as "command date" ie., which shows today date. Code:
: awk '{print $1";"$2";"$3";"$4";"$5=`date`}' <file1> can anybody help. |
Why not sed?
Code:
sed -i.bck "s/$/;$(date)/" file Code:
awk '{ "date" | getline current_time |
Its showing below error. :(
Code:
sed: illegal option -- i |
Quote:
Code:
sed "s/$/;$(date)/" file > /tmp/file.new |
Code:
awk '{ "date" | getline current_time |
Quote:
Code:
"shell command here" | getline varname However, this is a GNU awk extension. If you're not running it on a Linux machine, most likely it will fail. Better the sed solution without the -i option. |
Oh Thank you very much.. below command worked.
Code:
sed "s/$/;$(date)/" If you dont mind, i tried below command to get date in required format. didnt work. Code:
sed "s/$/;$(date "+%d/%m/%Y")/" |
Quote:
Code:
sed "s:$:;$(date +%d/%m/%Y):" file |
Awesome... you made my day... :) Thank you very much once again.
|
You're welcome! :)
|
All times are GMT -5. The time now is 06:01 PM. |