extract a part of a path like (input: /etc/exp/home/bin ====> output: exp)


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers extract a part of a path like (input: /etc/exp/home/bin ====> output: exp)
# 1  
Old 12-11-2008
extract a part of a path like (input: /etc/exp/home/bin ====> output: exp)

Hi, I need
to make some extraction . with the following input to get the right output.

input: /etc/exp/home/bin ====> output: exp

and

input: aex1234 ===> output: ex

Thanks for your help,
# 2  
Old 12-11-2008
What did you try so far?

Two possible ways:
Code:
echo '/etc/exp/home/bin' | awk -F/ '{print $3}'
exp

Code:
echo 'aex1234'| sed 's/.\(..\).*/\1/'
ex

# 3  
Old 12-16-2008
extract a part of a path like (input: /etc/exp/home/bin ====> output: exp)

Hi,
thanks for you help,
with this solution:
echo '/etc/exp/home/bin' | awk -F/ '{print $3}'
exp.

do you have another solution with sed command? because when a try your first solution in a shell script having 3 input parmeters, the {print $3} take another value.

now i'm looking for a sed command, if this command can solve the problem.

Thanks
# 4  
Old 12-16-2008
Totally depending on the new input. Show all kinds/possibilities of new input and I'll try to make it as generic as I can.
# 5  
Old 12-16-2008
Hi,
I have a solution with awk.

#!/bin/ksh

cd `dirname $0`/
APPLIHOME=`pwd | sed 's%/[^/]*$%%'`
echo "$APPLIHOME"

if [[ $# -lt 3 ]] then
echo
echo "ERROR : need 4 parameters "
echo "ERROR : Syntax error: [$shellprog.sh FILE DB PACKAGE ENV] "
exit 3
fi
echo "echo ${APPLIHOME} | awk -F '/' '{print \$3}'" > temp
PARAM=`ksh temp`
echo $PARAM

I add to your awk solution [\] to the print option ==>{print \$3} and it work.

Thanks for your help,
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Emergency UNIX and Linux Support

Need Help On REG EXP in unix

Respected All, I have a very big xml in that i want to search only below 3 lines. <target name ="UpgradePrimaryBox" depends ="configureBox1"> <echo> Finished Upgrading Primary Box </echo> </target> grep -i "<target.*UpgradePrimaryBox" this gives me the first line. then i need to match... (7 Replies)
Discussion started by: ameyrk
7 Replies

2. Shell Programming and Scripting

set output of linux cmd as a variable in .exp

I am trying to make a script to take commands from a .txt file ( line by line) and pass it using send ( used in another function ) what i am trying to achieve is : set nol "`grep '' ${exp_path2}/cmdlist.txt | wc -l `" as in shell script nol=`grep '' $exp_path2/cmdlist.txt | wc -l` ... (0 Replies)
Discussion started by: dixyantar
0 Replies

3. Shell Programming and Scripting

cp -p /home/* home/exp/*.date not working please help

:( ---------- Post updated at 01:51 AM ---------- Previous update was at 01:50 AM ---------- Not working ---------- Post updated at 02:04 AM ---------- Previous update was at 01:51 AM ---------- cp -p /home/* home/exp/*.`date` i am using this (4 Replies)
Discussion started by: rishiraaz
4 Replies

4. Shell Programming and Scripting

Regular exp in awk

Hi all, One small doubt, reg exp in awk, is it possible to extract the match of regular expression like in perl? eg: B R16288 Map3_NoCat B R16067 Map4_NoCat B R16647 Map3_NoCat B R16450 Map3_NoCat B R16106 Map6_NoCat B R16000 Map3_NoCat B R16395 Map3_NoCat B R16243 Map3_NoCat B R16023... (6 Replies)
Discussion started by: gvj
6 Replies

5. UNIX for Dummies Questions & Answers

exp command to extract particular rows

Hi, I'm new to unix so hopefully you can help! I'm using the below command to extract a tables contents and store it in a dmp file: exp OWNER/OWNER@LINK FILE=exp.dat TABLES=TABLE_TEST This works fine and dumps the table into the exp.dat file. What i can't figure out, is how to... (3 Replies)
Discussion started by: boijie
3 Replies

6. Shell Programming and Scripting

Perl reg exp

Hi, I am using the following piece of code for extracting some data from in between some tags ... $text =~ /<TAG1>(.*)<\/TAG1>.*<TAG2>(.*)<\/TAG2>.*<TAG3>(.*)<\/TAG4>.*<TAG5>(.*)<\/TAG5>/; $tag1=$1; print "\n$tag1"; But I am getting an error like Use of uninitialized value in... (1 Reply)
Discussion started by: King Nothing
1 Replies

7. Shell Programming and Scripting

reg exp for sed

$ cat file.txt asd <AA>dev <LL>def <RR>sha This works for me: $ sed -r 's/^ .*<LL>def/\t<LL>my/' file.txt asd <AA>dev <LL>my <RR>sha But, this does not work for me: $ sed -r 's/^\s+<LL>def/\t<LL>my/' file.txt asd ... (1 Reply)
Discussion started by: demoprog
1 Replies

8. Shell Programming and Scripting

reg exp question

Hi, Should be a difference between ']]*' and ']+' ? I use them in bash with sed and grep. Thanks (1 Reply)
Discussion started by: ynir
1 Replies
Login or Register to Ask a Question