The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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 05:13 PM
Text parsing question 98_1LE UNIX for Dummies Questions & Answers 3 03-24-2002 08:04 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 05-13-2008
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 567
Quote:
Originally Posted by muser View Post
Thanks for this code just prints a "20" and every file name on the same line.
There was a typo...xlsdate changed from "echo $i" to "echo $file"

Code:
for file in "$(echo dat*)"
do
   xlsdate=$(echo $file | 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
Reply With Quote
Forum Sponsor
  #9  
Old 05-13-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Also you probably mean "for file in dat*" rather than the silly echo. (^:
Reply With Quote
  #10  
Old 05-13-2008
Registered User
 

Join Date: May 2008
Posts: 6
Quote:
Originally Posted by robotronic View Post
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
Also, this works only with bash. You didn't specified which shell are you using. If not using bash, you may extract the same values through "cut" commands or something similar.
I used -

d=$(echo $xlsFile | cut -c4-5)
m=$(echo $xlsFile | cut -c7-8)
y=$(echo $xlsFile | cut -c10-11)

and it worked okay. Thanks!
Reply With Quote
  #11  
Old 05-13-2008
Registered User
 

Join Date: May 2008
Posts: 6
Quote:
Originally Posted by era View Post
Also you probably mean "for file in dat*" rather than the silly echo. (^:
This didn't work for me so I gave up trying to fix it.
Also, I was using Korn shell.

Thanks!
Reply With Quote
  #12  
Old 05-13-2008
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 567
Quote:
Originally Posted by era View Post
Also you probably mean "for file in dat*" rather than the silly echo. (^:
Spot on era
Reply With Quote
  #13  
Old 05-14-2008
Registered User
 

Join Date: Mar 2008
Posts: 83
hi Era,

hope you are doing well, can you answer few threads pls

sendmail help required
how to break mysql dump sql file

I am waiting for your kind reply.

Cheers,
Bash
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
sendmail

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0