Re: Remove the first 3 characters after reading each line
- From: Michal Nazarewicz <mina86@xxxxxxx>
- Date: Thu, 28 Sep 2006 22:23:43 +0200
nicetom786@xxxxxxxxx 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--
.
- References:
- Remove the first 3 characters after reading each line
- From: nicetom786
- Remove the first 3 characters after reading each line
- Prev by Date: Re: UNIX Shell Program
- Next by Date: Re: Thread cancellation
- Previous by thread: Re: Remove the first 3 characters after reading each line
- Index(es):
Relevant Pages
|