Words after / symbol


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Words after / symbol
# 1  
Old 09-19-2011
Words after / symbol

Hi,

I have the following directory:

/home/dragon/websphere/cells/profile/imp/001/

I want to put this in a shell script and get the values before and after cells by removing the '/'

Any idea how to make this possible?

Regards,
Dinesh
# 2  
Old 09-19-2011
Hi dbashyam,
can u plz tell what u want exactly...?

Quote:
/home/dragon/websphere/cells/profile/imp/001/
so u want the output as,
Quote:
homedragonwebspherecellsprofileimp001

..?
# 3  
Old 09-19-2011
Hi,

Actually I want to have the words before and after the word "cells"

Ofcourse it should include "/"

Thanks
Dinesh
# 4  
Old 09-19-2011
try this
Quote:
echo "/home/dragon/websphere/cells/profile/imp/001/" | awk -F'cells' ' {print $1}'
echo "/home/dragon/websphere/cells/profile/imp/001/" | awk -F'cells' ' {print $2}'
Use nawk if using solaris...
# 5  
Old 09-19-2011
So, Are you looking for something like below..?

command:echo /home/dragon/websphere/cells/profile/imp/001/ | cut -d/ -f1-4,6-8

output:/home/dragon/websphere/profile/imp/001
# 6  
Old 09-19-2011
Quote:
Originally Posted by dbashyam
I want to put this in a shell script and get the values before and after cells by removing the '/'

Any idea how to make this possible?
If I understand your meaning:

Code:
$ STR="/home/dragon/websphere/cells/profile/imp/001/"
$ OLDIFS="${IFS}" ; IFS="/"
$ set -- $STR
$ IFS="$OLDIFS"
$ echo $1
home
$ echo $2
dragon
$ echo $3
websphere
$ echo "${!#}" # ${!#} doesn't work in all shells
001
$

There may be better ways to do this depending on your shell, ways which don't mean replacing the $1/$2/... you already have.
# 7  
Old 09-19-2011
Post the sample output you expect from doing this.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace particular words in file based on if finds another words in that line

Hi All, I need one help to replace particular words in file based on if finds another words in that file . i.e. my self is peter@king. i am staying at north sydney. we all are peter@king. How to replace peter to sham if it finds @king in any line of that file. Please help me... (8 Replies)
Discussion started by: Rajib Podder
8 Replies

2. Shell Programming and Scripting

Search words in any quote position and then change the words

hi, i need to replace all words in any quote position and then need to change the words inside the file thousand of raw. textfile data : "Ninguno","Confirma","JuicioABC" "JuicioCOMP","Recurso","JuicioABC" "JuicioDELL","Nulidad","Nosino" "Solidade","JuicioEUR","Segundo" need... (1 Reply)
Discussion started by: benjietambling
1 Replies

3. UNIX for Dummies Questions & Answers

Deleting words between every appearance of two words

Hi there, newbie there. I've been browsing the forums hoping to find a solution that answers a problem similar to what I need, but haven't had much luck. Any help would be greatly appreciated. Thanks! I need to delete a bunch of text between every appearance of two words in a really large file... (3 Replies)
Discussion started by: lendl
3 Replies

4. UNIX for Dummies Questions & Answers

Replace the words in the file to the words that user type?

Hello, I would like to change my setting in a file to the setting that user input. For example, by default it is ONBOOT=ON When user key in "YES", it would be ONBOOT=YES -------------- This code only adds in the entire user input, but didn't replace it. How do i go about... (5 Replies)
Discussion started by: malfolozy
5 Replies

5. Shell Programming and Scripting

Gawk gensub, match capital words and lowercase words

Hi I have strings like these : Vengeance mitt Men Vengeance gloves Women Quatro Windstopper Etip gloves Quatro Windstopper Etip gloves Girls Thermobite hooded jacket Thermobite Triclimate snow jacket Boys Thermobite Triclimate snow jacket and I would like to get the lower case words at... (2 Replies)
Discussion started by: louisJ
2 Replies

6. Shell Programming and Scripting

How count the number of two words associated with the two words occurring in the file?

Hi , I need to count the number of errors associated with the two words occurring in the file. It's about counting the occurrences of the word "error" for where is the word "index.js". As such the command should look like. Please kindly help. I was trying: grep "error" log.txt | wc -l (1 Reply)
Discussion started by: jmarx
1 Replies

7. Shell Programming and Scripting

Remove whitespace after pipe symbol but not inside words

I have a file that looks like this: 102| #2 X 1/4-INCH| 30188| EA| FTW| A| NOT SERIAL TRACKING| NOT LOT TRACKING| TRUE| #2 X 1/4-INCH 102| #2 X 1/4-INCH| 30188| EA| VPS| A| NOT SERIAL TRACKING| NOT LOT TRACKING| TRUE| #2 X 1/4-INCH 102| #6 X 1/2"| ... (2 Replies)
Discussion started by: djehresmann
2 Replies

8. Shell Programming and Scripting

SED - delete words between two possible words

Hi all, I want to make an script using sed that removes everything between 'begin' (including the line that has it) and 'end1' or 'end2', not removing this line. Let me paste an 2 examples: anything before any string begin few lines of content end1 anything after anything before any... (4 Replies)
Discussion started by: meuser
4 Replies

9. Shell Programming and Scripting

Shell script to find out words, replace them and count words

hello, i 'd like your help about a bash script which: 1. finds inside the html file (it is attached with my post) the code number of the Latest Stable Kernel, 2.finds the link which leads to the download location of the Latest Stable Kernel version, (the right link should lead to the file... (3 Replies)
Discussion started by: alex83
3 Replies

10. Solaris

/usr/lib/passwdutil.so.1: symbol __nsl_fgetspent_r: referenced symbol not found

deleteing post (0 Replies)
Discussion started by: dshakey
0 Replies
Login or Register to Ask a Question