09-29-06 12:27 AM
nicetom786@yahoo.com writes:
> I have a file to read and after reading each line I want to strip off
> the first 3 characters and store in another variable.
> Cut command cuts the first 3 characters but I do not how to get the
> rest of letters.
> For ex:
> I have a line XXX_JOBNAME
> Here is the code
> cat jobs.txt |cut -c1-4
> This prints XXXX_.
> I want JOBNAME to be printed .But length of JOBNAME differs in each
> line.
>
>
> #Logic
>
> ext=".ksh"
> for line in `cat ~/jobs.txt`
Are you aware 'line' is misleading here? You don't read each line but
rather each word of the given file.
> do
> echo $line
> #remove the XXX_
> #put the cut logic here after ripping of 3
> characters and strore in another variale "job"
>
> #concanat .ksh to each job = $job
> job="$line$ext"
> echo $job
> #copy from SRC to taget
> #cp ~/src/job.ksh ~/target
> done
If you need to read the lines anyway you can omit cut as it introduces
another fork() which is not needed, ie:
#v+
while read line; do
cp -- ~/src/${line#????}.ksh" ~/target/
done <file-with-jobs
#v-
If you are sure the lines do not contain any funky characters and have
GNU mv, you can use something possibly faster:
#v+
cd ~/src
sed -ne 's/^....\(.*\)$/\1.ksh/p' <file-with-jobs | \
xargs mv --target-directory=~/target --
#v-
--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
.o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>--<jid:mina86*jabber.org>--ooO--(_)--Ooo--
[ Post a follow-up to this message ]
|