Re: Remove the first 3 characters after reading each line



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--
.



Relevant Pages

  • Re: Rita Mae Brown
    ... Rita Mae Brown has written many, many books on very diverse subjects. ... The cat mysteries written with Sneaky Pie Brown, ... However her animal characters and her plots ...
    (rec.pets.cats.anecdotes)
  • Re: Remove the first 3 characters after reading each line
    ... Cut command cuts the first 3 characters but I do not how to get the ... cat jobs.txt |cut -c1-4 ... echo $line ... Boeing Associate Technical Fellow ...
    (comp.unix.programmer)
  • Re: Remove the first 3 characters after reading each line
    ... I have a file to read and after reading each line I want to strip off ... Cut command cuts the first 3 characters but I do not how to get the ... I want JOBNAME to be printed .But length of JOBNAME differs in each ... You don't need the cat; ...
    (comp.unix.shell)
  • Re: Rita Mae Brown
    ... Rita Mae Brown has written many, many books on very diverse subjects. ... cat mysteries written with Sneaky Pie Brown, the female tiger she rescued, ... However her animal characters and her plots are ... superb in my opinion regarding her cat mysteries. ...
    (rec.pets.cats.anecdotes)
  • Re: Megami January
    ... > wanted to make an 18+ anime. ... you know exactly what that cat is usually thinking. ... >>They give the characters long skirts and manage to resist the urge to give ...
    (rec.arts.anime.misc)