- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- shell script help
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2009 03:58 PM
01-30-2009 03:58 PM
shell script help
run only if specific files are found in a directory. If files are found, then I need to fix them by removing bad characters only from the file names. Wanted to replace these bad characters with a # so we can do a lookup for what the file should be renamed. This lookup is inside another file. I'm trying to learn perl, but have not used it much. Here's a better example(I hope)of what I'm stuck with.
Files come in as
Payroll(1000171)20090112_163013.xml
Add in the # so new file would be something like Payroll#1000171#20090112_163013.xml so then I could use
ls Payroll*.xml | awk -F# '{print $2}'to do the lookup on a text file for the correct field name.
#1000171# = 0218
Once I have this match I'm not sure how to grab the correct match name out so I end up with the following...
Payroll_0218_20090112.xml
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2009 09:42 PM
01-30-2009 09:42 PM
Re: shell script help
Not sure but off the top of my head:
for FILE in `ls Payroll*.xml`
do
STRING=$(echo $FILE | awk -F"(" '{ print $2 }' | awk -F ")" '{ print $1 }')
#do the look up to get STRING2
$NEWFILENAME=#do some more awking as above to create this.
mv $FILE $NEWFILENAME
done
Saves putting the hashes in. Not sure whether the brackets should be quoted or escaped. You will have to experiment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2009 09:45 PM
01-30-2009 09:45 PM
Re: shell script help
$THEREST=4(echo $FILE|awk -F")" '{ print $2 }')
$NEWFILENAME="Payroll_"+$STRING2+"_"+$THEREST
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2009 09:56 PM
01-30-2009 09:56 PM
Re: shell script help
If you struggle to awk for the brackets, try adding a "-b" option to the ls. This may print the octal value rather than the bracket. Again, give this ago, I am not in front of a unix box at present.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2009 02:53 AM
01-31-2009 02:53 AM
Re: shell script help
1000181 = 0219
1000171 = 0218
And the number of files is small compared to records in FIELD.
ls Payroll\(*\)*.xml |
awk -F"[()]" -vFILE=FIELD '
{
s0 = $0
s1 = $1
s2 = $2
s3 = $3
save_FS = FS
FS = " "
stat = "grep \"" s2 "\" " FILE | getline
if (stat == 1)
print "mv \"" s0 "\"", s1 "_" $3 "_" s3
else
print "echo \"Cannot rename", $0 "\""
FS = save_FS
} '
This produces output like:
========================================================
mv "Payroll(1000171)20090112_163013.xml" Payroll_0218_20090112_163013.xml
mv "Payroll(1000181)20090112_163013.xml" Payroll_0219_20090112_163013.xml
echo "Cannot rename Payroll(1000191)20090112_163013.xml"
And then you can use a shell to execute the commands.