The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to print two sql query outputs side by side in excel prasee Shell Programming and Scripting 6 09-07-2007 11:20 PM
Need a hand. Please? alexcol Shell Programming and Scripting 1 09-26-2006 01:59 PM
Lets give Neo a hand. Optimus_P Post Here to Contact Site Administrators and Moderators 4 10-24-2003 06:37 AM
Give us a hand RichardB UNIX for Dummies Questions & Answers 3 05-06-2002 08:37 AM
Having a Unix system installed side to side with Windows? Pcslider UNIX for Dummies Questions & Answers 14 01-29-2002 03:21 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-16-2008
Registered User
 

Join Date: Jan 2008
Posts: 2
AWK how to strip from right hand side

guys,
i am writing a .ksh file to ssh to a remote machine and change all occurances of .ixf to .WIP like this :

-->>> for i in *.ixf do echo $i done mv $i $i.WIP exit <<---

--> this returns .ixf.WIP - i can live with that.

then i need to sftp from another remote machine, copy the files across to the new box and rename the file back to .ixf like this :

-->> for i in *.WIP; do echo $i; done; mv $i $i.ixf <<--

--> this returns .ixf.WIP.ixf - i can't live with this.

I need to strip WIP.ixf from the end, i think using awk but cannot get the syntax correct.
Any help here would be appreciated.
Thanks
Reply With Quote
Forum Sponsor
  #2  
Old 01-16-2008
Registered User
 

Join Date: Nov 2007
Posts: 10
use basename

I assume this is a unix box...
awk is a nuclear bomb, when all you need is a hammer.

Use basename (see example below)

#!/bin/ksh
for i in *.ixf; do
name=$(basename $i .ixf)
echo $name
mv $i $name.WIP
done
Reply With Quote
  #3  
Old 01-16-2008
Registered User
 

Join Date: Jan 2008
Posts: 2
If using 'sed ' is an option:
Code:
for i in *.WIP; do 
echo $i 
mv $i `echo $i | sed 's/\..*$//'`.ixf
done
Or if you want (GNU) awk, and assuming the 1st dot in the filename separates all the extension(s):
Code:
for i in *.WIP; do 
echo $i 
mv $i `echo $i | gawk -F . '{print $1}'`.ixf
done
HTH,
Zsoltik@
Reply With Quote
  #4  
Old 01-16-2008
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 570
Quote:
Originally Posted by angelolamberti View Post
guys,
i am writing a .ksh file to ssh to a remote machine and change all occurances of .ixf to .WIP like this :

-->>> for i in *.ixf do echo $i done mv $i $i.WIP exit <<---

--> this returns .ixf.WIP - i can live with that.

then i need to sftp from another remote machine, copy the files across to the new box and rename the file back to .ixf like this :

-->> for i in *.WIP; do echo $i; done; mv $i $i.ixf <<--

--> this returns .ixf.WIP.ixf - i can't live with this.

I need to strip WIP.ixf from the end, i think using awk but cannot get the syntax correct.
Any help here would be appreciated.
Thanks
Code:
for i in *.WIP
do
  echo $i
  OUTFILE=$(echo ${i%(\.[A-Z]*)}
  mv $i $OUTFILE
done
Reply With Quote
  #5  
Old 01-16-2008
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 737
Quote:
Originally Posted by zsoltika View Post
If using 'sed ' is an option:
Code:
for i in *.WIP; do 
echo $i 
mv $i `echo $i | sed 's/\..*$//'`.ixf
done
He need to remove the extension.

Code:
for i in *.WIP
do 
  mv $i `echo $i | sed 's/\.WIP$//'`
done
Reply With Quote
  #6  
Old 01-17-2008
Registered User
 

Join Date: Jan 2008
Posts: 2
Quote:
Originally Posted by n1djs View Post
I assume this is a unix box...
awk is a nuclear bomb, when all you need is a hammer.

Use basename (see example below)

#!/bin/ksh
for i in *.ixf; do
name=$(basename $i .ixf)
echo $name
mv $i $name.WIP
done


superb, thanks
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:38 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0