![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
If using 'sed ' is an option:
Code:
for i in *.WIP; do echo $i mv $i `echo $i | sed 's/\..*$//'`.ixf done Code:
for i in *.WIP; do
echo $i
mv $i `echo $i | gawk -F . '{print $1}'`.ixf
done
Zsoltik@ |
|
#4
|
|||
|
|||
|
Quote:
Code:
for i in *.WIP
do
echo $i
OUTFILE=$(echo ${i%(\.[A-Z]*)}
mv $i $OUTFILE
done
|
|
#5
|
|||
|
|||
|
Quote:
Code:
for i in *.WIP do mv $i `echo $i | sed 's/\.WIP$//'` done |
|
#6
|
|||
|
|||
|
Quote:
superb, thanks |
|||
| Google The UNIX and Linux Forums |