Help with dynamic value string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with dynamic value string
# 1  
Old 10-13-2011
Help with dynamic value string

Hi all,

Need help to seek string with dynamic value that always change?

Example string
Code:
JOB_WORK_STAFF_MARY_JANE_20111013_000000001.DAT

"JOB_WORK_STAFF_" and "_20111013_000000001.DAT" is static length.

How do I select the "MARY_JANE" in the middle of the string.
Please advice.

TQ.
# 2  
Old 10-13-2011
Code:
$ echo JOB_WORK_STAFF_MARY_JANE_20111013_000000001.DAT | awk 'BEGIN { FS="_"; OFS="_"; } { print $4, $5 }'
MARY_JANE

# 3  
Old 10-13-2011
Quote:
awk -F "_" '{print $4"_"$5}' <inputfile>
# 4  
Old 10-13-2011
thanks for reply friends,

but i might be not explaining the situation very well.

all your script work well if the string is
Code:
JOB_WORK_STAFF_MARY_JANE_20111013_000000001.DAT

but when i mean dynamic value. The string could be as
Code:
JOB_WORK_STAFF_MARY_JANE_20111013_000000001.DAT
JOB_WORK_STAFF_MARY_JANE_LANE_20111013_000000001.DAT
JOB_WORK_STAFF_MARYJANELANE_20111013_000000001.DAT

expected output
Code:
MARY_JANE
MARY_JANE_LANE
MARYJANELANE

# 5  
Old 10-13-2011
Code:
$ sed 's,JOB_WORK_STAFF_,,g;s,_20111013_000000001.DAT,,g' infile
MARY_JANE
MARY_JANE_LANE
MARYJANELANE
$

This User Gave Thanks to jayan_jay For This Post:
# 6  
Old 10-13-2011
thanks so much jayan_jay.

your code work as expected.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Korn Shell manipulating the string into dynamic currency number

Conversion of string into currency value.. ex1: number_of_positions=2 input_string=345987 Output= 345,987.00 ex2: number_of_positions=4 input_string=1345987 Output= 1,345,987.0000 Please respond as soon as possible edit by bakunin: we will gladly respond as soon as... (15 Replies)
Discussion started by: suren.bills
15 Replies

2. Shell Programming and Scripting

dynamic string searching for grep

hi my code is something like count=0 echo "oracle TABLESPACE NAME nd TARGET" while do count=`expr $count + 1` (1) tts_space_name$count=`echo $tts | cut -d "," -f$count` (2) target$count=grep $(tts_space_name$count)... (2 Replies)
Discussion started by: Gl@)!aTor
2 Replies

3. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

4. Shell Programming and Scripting

Complex find and replace only 1st instance string with dynamic combination

test.txt is the dynamic file but some of combination are fix like below are the lines ;wonder_off = ;wonder_off = disabled wonder_off = wonder_off = disabled the test.txt can content them in any order #cat test.xt ;wonder_off = ;wonder_off = disabled wonder_off = wonder_off =... (5 Replies)
Discussion started by: SilvesterJ
5 Replies

5. Shell Programming and Scripting

Help with dynamic script

Hey there, first post, somewhat-long-time lurker- This is on a Red Hat box Im working on a new site, and I have an idea for a dynamic CGI script to change who is "on call" Pretty much, it would pull next name from a text file each week to display it on the site, and just keeps cycling through... (3 Replies)
Discussion started by: rapenchukd
3 Replies

6. Shell Programming and Scripting

dynamic variable name

I found one post in another site with a solution for my problem the below solution should explain what I want. #!/bin/sh first="one" second="two" third="three" myvar="first" echo ${!myvar} But this gives error 'bad substitution' System info SunOS sundev2 5.9... (3 Replies)
Discussion started by: johnbach
3 Replies

7. UNIX for Advanced & Expert Users

Sql dynamic table / dynamic inserts

I have a file that reads File (X.txt) Contents of record 1: rdrDESTINATION_ADDRESS (String) "91 971502573813" rdrDESTINATION_IMSI (String) "000000000000000" rdrORIGINATING_ADDRESS (String) "d0 movies" rdrORIGINATING_IMSI (String) "000000000000000" rdrTRAFFIC_EVENT_TIME... (0 Replies)
Discussion started by: magedfawzy
0 Replies

8. Linux

how to dynamic DNS

hi i am using fedora core 5 and i already configured the dhcp server and the dns server but i want to configure dynamic dns to update the dns automatiklly thank you in advance (1 Reply)
Discussion started by: bondoq
1 Replies

9. Programming

export-dynamic

I load some dynamic libraries from main module (with dlopen). These libraries use 1 function from main module, therefore in Makefile I must use gcc -g -Wl,--export-dynamic,-rpath,./lib -o not not.o db.o -ldl -ldb -lpcap Note option --export-dynamic that is passed to the ELF linker. The... (4 Replies)
Discussion started by: Hitori
4 Replies

10. OS X (Apple)

Dynamic DNS

I have a need to regularly add all macs in our domain to dns. Ideally it would work like Wintel machines. Transparently and automatically. What are the tools, scripts, roadblocks to doing so? I'm not talking about DynDNS type of service here. This is the internal dns for where I work. (0 Replies)
Discussion started by: [MA]Flying_Meat
0 Replies
Login or Register to Ask a Question