Split a word in short words


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Split a word in short words
# 1  
Old 01-13-2010
Split a word in short words

Dear,

Can somebody help me with this?

I have a variable

Code:
TGT=T2DIRUPDAZ20070326VA

I want to get in variables some part of TGT. like this.

Code:
TGT1=UPDA
TGT2=20070326
TGT3= VA

These three variables have fixe position in variable TGT.

Can you help me with shell expression to get these three variables(TGT1,TGT2,TGT3) from TGT ?

Thanks.

Last edited by zaxxon; 01-13-2010 at 07:39 AM.. Reason: use code tags please, ty
# 2  
Old 01-13-2010
Code:
#! /bin/bash

TGT=T2DIRUPDAZ20070326VA;
TG1=${TGT:5:4};
TG2=${TGT:10:8};
TG3=${TGT:18};
echo $TG1 $TG2 $TG3;

# 3  
Old 01-13-2010
Possible way with awk:
Code:
$> TGT=T2DIRUPDAZ20070326VA
$> TGT1=`echo $TGT| awk '{print(substr($0,6,4))}'`
$> echo $TGT1
UPDA

The 2 other should be no problem now.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract words before and after a certain word.

I have a sample text file with file name: sample.txt The text file has the following text. this is an example text where we have to extract certain words before and after certain word these words can be used later to get more information I want to extract n (a constant) words before and... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

2. Shell Programming and Scripting

Read a File line by line and split into array word by word

Hi All, Hope you guys had a wonderful weekend I have a scenario where in which I have to read a file line by line and check for few words before redirecting to a file I have searched the forum but,either those answers dint work (perhaps because of my wrong under standing of how IFS... (6 Replies)
Discussion started by: Kingcobra
6 Replies

3. UNIX for Dummies Questions & Answers

Replacing word and Capitalize words after

I have an assignment and I am not sure what to do. In Unix, I use PuTTY change the semicolon (;) to a period, and capitalize the first letter of the word immediately after it. I know change command is M-% and "." so only one semicolon is changed but I am not sure how to... (1 Reply)
Discussion started by: kathrut43
1 Replies

4. Shell Programming and Scripting

Split file by number of words

Dear all I am trying to divide a file using the number of words as a condition. Alternatively, I would at least like to be able to retrieve the first x words of a given file. Any tips? Thanks in advance. (7 Replies)
Discussion started by: aavv
7 Replies

5. Shell Programming and Scripting

How to get a known word between two known words using awk

hi I have posted it earlier but i was unable to put my exact problem.This time posting in parts. I have a text file which i had transferred to UNIX.It has strings like: alter table table_name add (column_name); as well as modify options. now i need to read the table name between alter... (3 Replies)
Discussion started by: alisha
3 Replies

6. Shell Programming and Scripting

Print all the words after a match word

Hi, I want to print all words till the last word after the match of "ERROR" word. For e.g. I'll get an sqlplus error with e.g. 1 $ ./calltest_fn.ksh var test_var:=test_fn1; calltest_fn.ksh file1 file2 file3 ERROR at line 4: ORA-06550: line 4, column 11: PLS-00201: identifier... (5 Replies)
Discussion started by: dips_ag
5 Replies

7. UNIX for Dummies Questions & Answers

Split words from 2 files and printing in csv

My task requires me to add a column to my existing csv file.This column will be populated with data that is dependant on data in another column.The script will go through the data in column A and create new cells in column B that will be dependent on column A data. Thanks (1 Reply)
Discussion started by: Adan Daroski
1 Replies

8. UNIX for Dummies Questions & Answers

Split words from 2 files and printing in csv

Hello Everyone, (1 Reply)
Discussion started by: thankful123
1 Replies

9. Shell Programming and Scripting

To split a string to obtain the words delimited by whitespaces

Please can someone thow some light what is the best way to split a string to obtain the words delimited by whitespaces. (4 Replies)
Discussion started by: Sudhakar333
4 Replies

10. UNIX for Dummies Questions & Answers

return a word between two words

how do i get a word that exists between two words eg: this is bryan My input to command would be this and bryan and output should be 'is' Is there a command i can use? (4 Replies)
Discussion started by: bryan
4 Replies
Login or Register to Ask a Question