The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Awk:Find length of string omitting quotes jayakumarrt Shell Programming and Scripting 2 05-09-2008 03:48 AM
omitting lines from file A that are in file B gneen Shell Programming and Scripting 14 02-20-2008 05:33 AM
Get the words.. kakashi_jet Shell Programming and Scripting 10 07-31-2006 09:30 AM
Omitting some filenames for commands to process milhan Shell Programming and Scripting 5 05-19-2006 06:49 PM
Extracting only Alphabets from a value amitkhiare UNIX for Advanced & Expert Users 2 02-22-2006 03:24 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-27-2009
coolrekz coolrekz is offline
Registered User
  
 

Join Date: May 2009
Posts: 3
Post Omitting the last 2 alphabets in the words

Hi Guys,

Bit new to Unix shell scripting so this question might seems little kiddish for you.

what im trying to achieve here is :

I have file which is compressed like Account_52320090605076_log.Z

so in my shell script i call this file also as one of my parameters

like

./Information.sh DBNAME USERNAME DIREC_LOC Account_52320090605076_log.Z

what i need here is

1. Check if the file has a .Z or .z at its end .
if yes then
uncompress it

after uncompress the DUMPFILE_NAME should have a new paramater without the .Z extension

2. If no then proceed with the next step


my script looks like this

#!/bin/ksh

DB_NAME=$1
USER_NAME=$2
DIR_LOC=$3
DUMPFILE_NAME=$4
LINE=$DUMPFILE_NAME; export LINE
VAR=`echo $LINE |awk -F. '{print $3}`;export VAR
echo $VAR


if [ "$VAR" = "z" ] || [ "$VAR" = "Z" ]
then

uncompress $DUMPFILE_NAME

chmod 744 `echo $LINE |awk -F. '{print $1"."$2}'`

DUMPFILE_NAME=$LINE |awk -F. '{print $1"."$2}' ; export DUMPFILE_NAME

echo $DUMPFILE_NAME

fi

echo $DUMPFILE_NAME


but it seems like lines doesn't fetch me the correct result , could some one help and let me know a correct command that i can use for this situation.

thx
rekz
  #2 (permalink)  
Old 05-27-2009
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474
Did u try to test it ?..

Code:
VAR=`echo $LINE |awk -F. '{print $2}`
instead of $3.

other way :

To get extn

Code:
TEST>echo "Account_52320090605076_log.Z" |sed 's/.*\.\(.*\)/\1/'
Z
To get file name with out extn
Code:
 
TEST>echo "Account_52320090605076_log.Z" |sed 's/\(.*\)\..*/\1/'
Account_52320090605076_log

Last edited by panyam; 05-27-2009 at 08:43 AM..
  #3 (permalink)  
Old 05-27-2009
coolrekz coolrekz is offline
Registered User
  
 

Join Date: May 2009
Posts: 3
Thumbs up

To good Guru , it worked perfectly .. thx a ton
  #4 (permalink)  
Old 05-27-2009
colemar colemar is offline
Registered User
  
 

Join Date: Apr 2009
Location: Trento, Italy
Posts: 116
.Z suffix is not really a good test to ascertain if a file is compressed with compress.

I believe this is better:

Code:
if [[ $(file $MYFILE) = *"compressed data"* ]]
  #5 (permalink)  
Old 05-27-2009
coolrekz coolrekz is offline
Registered User
  
 

Join Date: May 2009
Posts: 3
Great this sound good and better , it also make coding less
Closed Thread

Bookmarks

Tags
alphabets, omitting, rekz

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:21 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0