Omitting the last 2 alphabets in the words


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Omitting the last 2 alphabets in the words
# 1  
Old 05-27-2009
Java 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  
Old 05-27-2009
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 09:43 AM..
# 3  
Old 05-27-2009
MySQL

To good Guru , it worked perfectly .. thx a ton Smilie
# 4  
Old 05-27-2009
.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  
Old 05-27-2009
Great this sound good and better , it also make coding less
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Replace alphabets from certain positions

Hi all, I have column 2 full of values like HIVE4A-56 and HIVE4-56. I want to convert all values like HIVE4A-56 to HIVE4-56. So basically I want to delete all single alphabets before the '-' which is always preceded by a number. Values already in the desired format should remain unchanged... (4 Replies)
Discussion started by: ames1983
4 Replies

2. Shell Programming and Scripting

Omitting sections of file that contain word

I have a configuration file that contains hundreds of these chunks. Each "chunk" is the section that begins with "define service {" and ends with "}". define service { check_command check_proc!java hostgroup_name service_description ... (5 Replies)
Discussion started by: SkySmart
5 Replies

3. Shell Programming and Scripting

Omitting directory

Hello, Am trying to copy log files from one directory to other directory but the files are with date format i need it for some specific date like this find . -name 'log.2011020*' -exec cp ~/temp {} \; but its displaying the below error cp: omitting directory `/home/l828117/temp' cp:... (2 Replies)
Discussion started by: thelakbe
2 Replies

4. Shell Programming and Scripting

filter unique alphabets

Filter unique alphabets (bold) from input Thanx +SRR015270.1 HWI-B10_3_6069:2:1:653:875 length=32 SZZZZZZZZZZZZXZZZXZZZOECZZIZHUEM +SRR015270.2 HWI-B10_3_6069:2:1:455:450 length=32 ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZTT @SRR015270.3 HWI-B10_3_6069:2:1:453:499 length=32... (2 Replies)
Discussion started by: repinementer
2 Replies

5. Shell Programming and Scripting

Filter certain number of alphabets

filter the ones (ex:>1279_17_27_F3) that have 50letters (ABABABACACACACACAADADADADABABABABAACACACACACACAACAC) in input. And others that are less than 50 have to be ignore and the ones with more than 50 have to trimmed to first 50 letters. Thanx >1279_16_1960_F3 A >1279_16_2010_F3 BCCC... (2 Replies)
Discussion started by: ruby_sgp
2 Replies

6. Shell Programming and Scripting

Unix Remove repetitive alphabets

Hi, I am trying to write a script that will take 2 or more instances of repetitive alphabets (ZZ) to be removed from a field. This should only happen from beginning and end of a field. For Example : Input File a) ZZZIBM Corporation b) ZZZIBM Corporation ZZZZZ b) IBM ZZZ... (26 Replies)
Discussion started by: msalam65
26 Replies

7. Shell Programming and Scripting

Checking for Alphabets

echo -n "read this also:" read NewAuthor if ]' ) ] ; then echo "its a digit" else echo "something else" fi Hey guys , i am trying to do a search to check if the input is using alphabets and nothing else. I tried using ] and ] but none seems to work When i use digit, it read 22.k... (5 Replies)
Discussion started by: gregarion
5 Replies

8. Shell Programming and Scripting

Awk:Find length of string omitting quotes

Hi , I have a file named "sample" having the data as follows. "663005487","USD",0,1,"NR" If i give like a=`awk -F ',' '{printf length($2)}' sample` (Trying to find length of second field)I should get the output for the above as 3 (Omitting double quotes) not 5. How to do this..... (2 Replies)
Discussion started by: jayakumarrt
2 Replies

9. Shell Programming and Scripting

Omitting some filenames for commands to process

hello all, this topic might have been discussed but I couldn't find it with searching. I am trying to do a for command that will dos2unix files one by one and save it under directory called backup (backup is in the same directory with other files). When I do: for i in * do dos2unix $i... (5 Replies)
Discussion started by: milhan
5 Replies

10. UNIX for Advanced & Expert Users

Extracting only Alphabets from a value

Hi, I have file name (abcd001). I want to extract on the alphabets from this file name. I don't want the numeric part of it. Once i extract the alphabets the i can search for all those file. Could anyone help on this. Thanks in advance (2 Replies)
Discussion started by: amitkhiare
2 Replies
Login or Register to Ask a Question