1828837 Members
2638 Online
109985 Solutions
New Discussion

Script help please

 
SOLVED
Go to solution
Paula J Frazer-Campbell
Honored Contributor

Script help please

Help from script experts please.

Dir listing gives these file names

uv8980926993aa
uv8981027062aa
us9105010894aa
us9047009985aa

I require to pull out the 3 to 7th chars,

I.e.
uv8980926993aa
to become
89809

I have got this far :-

ll | awk '{print $9}' | sed "s/^uv//" | sed "s/^us//" | sed "s/aa//"

To give this:-

8980926993
8981027062
9105010894
9047009985

But what next ??


Thanks in advance

Paula
If you can spell SysAdmin then you is one - anon
14 REPLIES 14
harry d brown jr
Honored Contributor
Solution

Re: Script help please



ll | awk '{print substr($9,3,5)}'

live free or die
harry
Live Free or Die
Frederic Sevestre
Honored Contributor

Re: Script help please

Hi,

What is about :

ll | awk '{print $9}' | cut -c3-7

Regards
Fr??d??ric
Crime doesn't pay...does that mean that my job is a crime ?
Steven Gillard_2
Honored Contributor

Re: Script help please

Try using 'cut':

$ ls | cut -c 3-7

Regards,
Steve
harry d brown jr
Honored Contributor

Re: Script help please

or

ll | awk '{print $9}' | sed "s/uv\([0-9]\{5\}\)\(.*$\)/\1/"


live free or die
harry
Live Free or Die
Steve Steel
Honored Contributor

Re: Script help please

Hi

This to check.script with dir as parameter

file=$1
for f in $(ls -1 $file|sed -e 's:^.*/::g')
do
echo $f"|"$(echo $f|cut -c3-7)
done

This to do your option.

file=$1
for f in $(ls -1 $file|sed -e 's:^.*/::g')
do
echo $(echo $f|cut -c3-7)
done

Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
MANOJ SRIVASTAVA
Honored Contributor

Re: Script help please

Hi Paula


Try this


ls | awk '{print$9}' | cut -c 3-7


Manoj Srivastava
Ceesjan van Hattum
Esteemed Contributor

Re: Script help please

Hi, just use
cat input | cut 3-7

Greetings,
Ceesjan
Paula J Frazer-Campbell
Honored Contributor

Re: Script help please

Woa

Enough already ---


I will check out and assign points.

Thanks


Paula
If you can spell SysAdmin then you is one - anon
James R. Ferguson
Acclaimed Contributor

Re: Script help please

Hi Paula:

Just for grins-and-giggles (although Harry's first solution using the 'substr' function of 'awk' my choice too):

# ls -l|tr -s " " "\t"|cut -f9|cut -c3-7

Regards!

...JRF...
Darrell Allen
Honored Contributor

Re: Script help please

Hi Paula,

More confusion...

If use ll, "grep -v ^total" needs to be added. I'd use ls instead of ll. You can explicitly say "ls -1" for one column output but ls will do that by default when it's output is piped to another command.

My vote for speed and simplicity is Steven Gillard's:
ls | cut -c 3-7

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Mark Greene_1
Honored Contributor

Re: Script help please

Paula,

Playing with the uv spool files I see! Keep in mind that sometimes files in the directory no longer will be in the uv index file and therefore will not be accessible as hold entries from the uv commandline. OTOH, this also means that you can safely wack them, as far as uv is concerned.

HTH
mark
the future will be a lot like now, only later
Paula J Frazer-Campbell
Honored Contributor

Re: Script help please

Mark

Yes wonderful universe - I am writing an old file cleanup routine and intend to fire my results at:-

usm -k

As as you know Unix file name and Universe file name when using the usm are different.

Instead of just doing an rm on them I thought it safer to let the universe command deal with them.

Et Al.

All answer were worth 10 points - there is certainly more than one way to skin a cat.


:^)

Thanks

Paula
If you can spell SysAdmin then you is one - anon
Mark Greene_1
Honored Contributor

Re: Script help please

Paula,

Yes, been there, done that. Some caveats: you have to run this as root, but you can do it in cron. You also have to allow for the usm command to fail because the entry in the uv index is gone, so it won't remove the file. You can get around that like this:

usm -k || rm -f [file]

also be aware that not all of the usm/usa command options work, or work as advertised.

HTH
mark
the future will be a lot like now, only later
H.Merijn Brand (procura
Honored Contributor

Re: Script help please

l1:/tmp 107 > ls u*
us9047009985aa us9105010894aa uv8980926993aa uv8981027062aa
l1:/tmp 108 > perl -le 'for(grep s/^u[vs](\d{5}).*/$1/, ) { print }'
90470
91050
89809
89810
l1:/tmp 109 >
Enjoy, Have FUN! H.Merijn