Need rm script help ASAP

I need your expertise anyone. I'm trying to remove part of a id # in a script. Reason, the part of the id is a underscore that is making my life impossible. I simply cannot handle all the requests and modify every single one in vi or edt. So I wanted to modify the script..

For example _1234567.RP

How would I remove just the "underscore" and nothing else ?

How would I then let it account for the rest of the 7 digits and the extension ?

Thanks
simon2000

Well in ksh (why do people NEVER reveal which language they are using?) it is easy:

#! /usr/bin/ksh
x=_1234567.RP
y=${x#?}
echo $y
exit 0

Hi Perderabo,

Could you pl explain what do # and ? after x do.

Thanx

The # says to remove a leading pattern. The ? is a pattern that matches a single character. Put them together and you are stripping off the first character.

Are the PartNumbers's in the script file or in a seperate flat ASCII file?

A quick perl script could be generated to go through the script line-by-line and remove the leading underscore by pattern.

If the PartNumbers are in a seperate flat ASCII file, sed would probably be a quick solution.

just to expand on his code.

cd path/to/files
for files in `ls`;do
     for lines in `cat $files`;do
          y=${lines#?}
          echo $y >> new.file
     done
done

or in sed

sed 's/^_//g' * >> contents_of_all_files_in_current_directory.txt

Posix shell. sorry.. /sh

thanks for the help..

would this have worked maybe ?

#! /usr/bin/sh

if
[ "$X"="_"]
then
echo "_1234567.RP to be fixed"

rm *_*1234567.RP

fi

Your input would be greatly appreciated once again..

thanks
simon

why dont you try it and let us know if it worked.

with that kind of response it sounds as if you did not try anything befor you posted, and your just looking for an answer.

it did not work.. it is missing something. I guess I asked incorrectly. I'll remember to ask appropriately so people like you don't get upset.

Yet another way to truncate leading "_"

#!usr/bin/sh

result=`echo "1234567.RP" | tr -d ""`
echo $result

Thanks & Regards
Suresh Kumar S.M.

simon2000, the solution that you posted seems so far off the mark that I'm really sure what to say about it. First, out of the blue you are testing the value of a variable called X. Where did X did it's value? And that rm command throws me. Why are we deleting files? At this point I'm not really sure that I understand what problem you are trying to solve.

Perderabo - Thanks for the help. I was attempting to remove an underscore that's all. I thought the "rm" was the way to go. But actually the tr -d _ appears to be the most logical way to go.

sorry to put you and the others through so much trouble.

back to working on my scripting..

simon2000