| Author |
Remove the first 3 characters after reading each line
|
|
| nicetom786@yahoo.com 2006-09-28, 7:00 pm |
| Hi ,
I am new to unix .
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`
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
pls guide.
Thanks
| |
| Bjorn Reese 2006-09-28, 7:00 pm |
| nicetom786@yahoo.com wrote:
> 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.
[...]
> cat jobs.txt |cut -c1-4
cat jobs.txt | cut -c5-
--
mail1dotstofanetdotdk
| |
| Fred Kleinschmidt 2006-09-28, 7:00 pm |
|
<nicetom786@yahoo.com> wrote in message
news:1159461178.490764.15280@m7g2000cwm.googlegroups.com...
> Hi ,
> I am new to unix .
> 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.
cat jobs.txt | cut -c5-
>
>
> #Logic
>
> ext=".ksh"
> for line in `cat ~/jobs.txt`
> 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
>
>
> pls guide.
> Thanks
>
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project
| |
| Måns Rullgård 2006-09-28, 7:00 pm |
| Bjorn Reese <breese@see.signature> writes:
> nicetom786@yahoo.com wrote:
>
> [...]
>
> cat jobs.txt | cut -c5-
UUOC
--
Måns Rullgård
mru@inprovide.com
| |
| Michal Nazarewicz 2006-09-28, 7:00 pm |
| 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--
|
|
|
|