Remove the first 3 characters after reading each line
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Remove the first 3 characters after reading each line




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Remove the first 3 characters after reading each line  
nicetom786@yahoo.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-28-06 06:21 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






[ Post a follow-up to this message ]



    Re: Remove the first 3 characters after reading each line  
Bjorn Reese


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-28-06 06:21 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





[ Post a follow-up to this message ]



    Re: Remove the first 3 characters after reading each line  
Fred Kleinschmidt


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-28-06 06:21 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







[ Post a follow-up to this message ]



    Re: Remove the first 3 characters after reading each line  
Måns Rullgård


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-28-06 06:21 PM

Bjorn Reese <breese@see.signature> writes:

> nicetom786@yahoo.com wrote:
> 
> [...] 
>
> cat jobs.txt | cut -c5-

UUOC

--
Måns Rullgård
mru@inprovide.com





[ Post a follow-up to this message ]



    Re: Remove the first 3 characters after reading each line  
Michal Nazarewicz


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
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 ]



    Sponsored Links  




 





   All times are GMT. The time now is 04:25 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register