|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Concatenation in awk not working
Hello I want to achieve the following. However the concatenation is not working Code:
mv `ls -ltr *myfile*.log|awk '{print $9}'` `ls -ltr *myfile*.log|awk '{print `date +'%d%m%y%k%M%S'` $9}'`I tried Code:
awk '{x=`date +'%d%m%y%k%M%S'` print $x "" $9}'
awk '{x=`date +'%d%m%y%k%M%S'` print x "" $9}'But nothing is working Please help me on this Thanks and Regards Chetanz |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
You're just trying to prepend the date to filename? Code:
date=$(date +'%d%m%y%k%M%S')
for file in *myfile*.log; do
mv "$file" "${date}${file}"
done |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
NO backtics in awk, please! And, using nested backtics like in your mv command needs escaping them. That's why backtics are deprecated and users are encouraged to use the $(...) form of command substitution. In order to get the output of a shell command into an awk variable, you need to use command, pipe, and getline like in Code:
$ awk '{"date +%d%m%y%k%M%S"|getline x; print x}' file
010313114139BTW - the way you use the ls -ltr construct is far from optimal and would not fit mv usage, as both invocations may yield multiple files that mv does not handle that way. What's the reason to use it the way you do? Maybe there's other, improved ways to achieve the desired result. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| awk for concatenation of column values | Gussifinknottle | UNIX for Dummies Questions & Answers | 10 | 01-01-2013 10:23 AM |
| Awk expressions working & not working | vibhor_agarwali | UNIX for Advanced & Expert Users | 12 | 10-12-2011 11:52 AM |
| Awk concatenation in different lines | posner | Shell Programming and Scripting | 4 | 06-29-2010 10:54 AM |
| String concatenation not working in a loop | LostInTheWoods | Shell Programming and Scripting | 5 | 01-26-2010 04:09 AM |
| cannot get logic for concatenation awk | user_prady | Shell Programming and Scripting | 7 | 12-10-2007 02:09 AM |
|
|