Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Korn Shell Strings (AIX 5.3)

Status
Not open for further replies.

tbohon

Programmer
Apr 20, 2000
293
US
I have a file name that I need to break up and can't seem to get it to work.

Filename pattern is surgerytestYYYYMMDD.txt where YYYYMMDD is the current date. Example: surgerytest20051214.txt

What I need to do is modify the name to delete the date, e.g., from the above create a variable with the contents of
surgerytest.txt .

I've tried using the ${r:1:11} but the AIX version of ksh becomes violently ill when it hits that line.

Thoughts?

I'd like to do this in my script if possible, otherwise can make it happen in a Perl script ... just trying to keetp it as simple as possible.

Thanks, as always, in advance for any assistance.

Tom

"My mind is like a steel whatchamacallit ...
 
Something like this ?
echo ${r%????????.???}.${r#*.}

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV, works great - thanks.

MRN, interesting thread - I've bookmarked it for future reference.

One more question for the two of you if I may ...

I want to apply this process to all of the files in a directory called files_in ... there should only be one file a day but it's possible, due to timing issues, that we could have two or maybe even three files waiting there. Is there a quick and easy way to put this into a loop for all .txt files in the directory?

Thanks again. I appreciate the assist.

Tom

"My mind is like a steel whatchamacallit ...
 
It's as simple as...

Code:
for r in *.txt
do
    (your code here)
done

Annihilannic.
 
That's what I thought ... but it ends up moving the entire directory AND the contents to the files_out directory, then deleting the original files_in directory.

What I actually entered was

Code:
for list in `ll files_in/`
do
   <code>
done

I have one of our local Unix gurus looking at it - he didn't see anything wrong at first glance but there's obviously something strange happening.

Thanks!

Tom

"My mind is like a steel whatchamacallit ...
 
It depends on what the output of the ll files_in/ command was... if it included the name of the directory in the output of that command, the directory itself would be processed as well, just like the files.

ll is not a 'standard' command, it is most likely an alias, so I can't simulate it at my end. Type alias ll to check what it is defined as.

Annihilannic.
 
Figured it out - a misplaced '$' in a variable name was causing the problem. Corrected, tested, works great.

Of course, right after I fixed it - while still patting myself on the back for being so clever - I was told that they've changed the way they want the files processed so this won't even be necessary. Good think I like learning things just to learn them, huh? :)

Thanks all for the assist - great response as always.

Best of the holiday season,

Tom

"My mind is like a steel whatchamacallit ...
 
You can also try this script amend the find command to meet your needs.

##########################################################################
# Shellscript: allfiles - apply command to all files in all subdirectories
##########################################################################

PN=`basename "$0"`


Usage () {
echo >&2 "$PN - apply command to all files in all subdirectories
usage: $PN command [arg ...]

The given command will be applied to all files in the current
and in all subdirectories -- USE WITH CARE."
exit 1
}

[ $# -lt 1 ] && Usage

find * -type f -print | xargs "$@"

Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant."

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top