![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| parsing xml with awk/sed | ricgamch | Shell Programming and Scripting | 3 | 05-28-2008 07:39 AM |
| Awk Parsing | bombcan | Shell Programming and Scripting | 2 | 04-24-2008 11:45 AM |
| parsing | tungaw2004 | UNIX for Dummies Questions & Answers | 15 | 03-27-2007 05:33 PM |
| XML parsing | handak9 | High Level Programming | 1 | 11-01-2004 04:13 PM |
| Text parsing question | 98_1LE | UNIX for Dummies Questions & Answers | 3 | 03-24-2002 07:04 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi Guys,
I was wondering if you could help me out - I have a directory /home/users/datafiles/ which contain files "dat dd-mm-yy.xls" I am trying to write a script which does the following - (1) loops through all the files (2) retrieves the dd-mm-yy string and converts it into a yyyymmdd to be stored as a variable for xlsFile in dat*.xls do ##scripting echo $xlsDate echo $formattedDate echo $xlsFile done E.g. If I had file "dat 10-01-08.xls", these 3 would be the result - 10-01-08 20080110 dat 10-01-08.xls Thanks in advance, |
| Forum Sponsor | ||
|
|
|
|||
|
Code:
for file in "$(echo dat*)"
do
xlsdate=$(echo $i | awk '{split($2,a,"\.xls");print a[1]}')
fmtdate=$(echo $xlsdate | awk -F"-" '{for(i=NF;i>=1;i--) s=s""$i;print "20"s}')
echo $xlsdate
echo $fmtdate
echo $file
done
|
|
|||
|
Quote:
|
|
|||
|
Thanks for this code just prints a "20" and every file name on the same line.
|
|
||||
|
Uh! I wrote "x" variable instead of "xlsFile"
Code:
for xlsFile in dat*.xls
do
d=${xlsFile:4:2}
m=${xlsFile:7:2}
y=${xlsFile:10:2}
xlsDate="$d-$m-$y"
formattedDate="20$y$m$d"
echo $xlsDate
echo $formattedDate
echo $xlsFile
done
|
||||
| Google The UNIX and Linux Forums |