Sponsored Content
Top Forums Shell Programming and Scripting Extract string in shell script Post 302536141 by asak on Monday 4th of July 2011 08:00:02 AM
Old 07-04-2011
Error Extract string in shell script

Hi All,

i've a string
Code:
/u/asak/DATE/TEST_LOGS/20110704_033429_test11_w_2_120/HDD/test11_w_2_12/hd-120

i need to extract string which is test11_w_2_120, this can be start with anything, numbers, characters with underscore etc.. but the time stamp 20110704_033429_ with two underscores will be there and string ends with /.

string may contain like this also 20110704_043944_test11_22_w_2_120, but it always has timestamp with two underscores. even the path may change (/u/asak/DATE/TEST_LOGS) only timestamp with two underscore is constant.

i need it in shell script.
please help ...

Thanks in advance.

Regards,
ASAK
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

command/script to extract a substring from a string

I have a long string "<ID type="Oid">{}</ID>" I need to extract "GigabitEthernet0/1" from the above string. How can it be done? :) (5 Replies)
Discussion started by: girisha
5 Replies

2. Shell Programming and Scripting

Using Awk in shell script to extract an index of a substring from a parent string

Hi All, I am new to this shell scripting world. Struck up with a problem, can anyone of you please pull me out of this. Requirement : Need to get the index of a substring from a parent string Eg : index("Sandy","dy") should return 4 or 3. My Approach : I used Awk function index to... (2 Replies)
Discussion started by: sandeepms17
2 Replies

3. Shell Programming and Scripting

Shell Script to extract Soft

...Software and Disk information... Hey guys.... I need to extract a bunch of information from a set of servers running Solaris 10 where I need to know for each server: - all OS Versions and patch levels - 3rd party COTS or opensource software/processes running on all servers (several... (0 Replies)
Discussion started by: northern1969
0 Replies

4. Shell Programming and Scripting

Shell Script to extract string from file

Hello, I have a file whose contents look as follows <ID="24" name="Kobe Bryant" Position="Shooting Guard"> <name="Artest" Position="Forward" ID="37"> I need to get the output which contains everything in the quotes for Position (Shooting Guard and Forward). I tried this but it doesn't work... (3 Replies)
Discussion started by: grajp002
3 Replies

5. UNIX for Dummies Questions & Answers

Comparing a String variable with a string literal in a Debian shell script

Hi All, I am trying to to compare a string variable with a string literal inside a loop but keep getting the ./testifstructure.sh: line 6: #!/bin/sh BOOK_LIST="BOOK1 BOOK2" for BOOK in ${BOOK_LIST} do if then echo '1' else echo '2' fi done Please use next... (1 Reply)
Discussion started by: daveu7
1 Replies

6. Shell Programming and Scripting

Help with shell script to extract certain information

Hi, I have a file which I need to programmatically split into two files. All the information in the file before pattern "STOP HERE" is to be stripped and output into one file while everything after "STOP HERE" is to be output into a separate file. I would appreciate help on how to do... (8 Replies)
Discussion started by: PTL
8 Replies

7. Shell Programming and Scripting

Script Shell Extract substring

Hi all, Please, i'd like to extract string just before '.fr'. Here is some lines of my file: g-82.text.text1.fr.worker1 g-xx.yyyyyy.zzzz.fr.worker2 i'd like to extract this text: g-82.text.text1 g-xx.yyyyyy.zzzz Please, which command i have to use in my script shell ? ... (16 Replies)
Discussion started by: chercheur111
16 Replies

8. UNIX for Beginners Questions & Answers

Shell script to extract data in a file

I have this 5GB file, and i want to extract from the file particulars pattern. this is my script: // count=`grep -wc "MSISDN" file_name` k=1 >OUTPUT >OUTPUT_Final while do cat file_name | awk -F":" -v var="$k" '$1=="MSISDN" {m++}m==var{print; exit}' >> OUTPUT cat file_name |awk -F":"... (33 Replies)
Discussion started by: gillesi
33 Replies

9. Shell Programming and Scripting

How can I extract digits at the end of a string in UNIX shell scripting?

How can I extract digits at the end of a string in UNIX shell scripting or perl? cat file.txt abc_d123_4567.txt A246_B789.txt B123cc099.txt a123_B234-012.txt a13.txt What can I do here? Many thanks. cat file.txt | sed "s/.txt$//" | ........ 4567 789 099 012 13 (11 Replies)
Discussion started by: mingch
11 Replies

10. Shell Programming and Scripting

Enhance existing script: Extract Multiple variables & Input in an echo string

Hi Experts I need your help to optimize my script to execute better as I have nearly 1M records & the script is taking close to 40 minutes to execute, so would need support on a faster alternative. Input: file {"house":"1024","zip":"2345","city":"asd","country":"zzv"}... (2 Replies)
Discussion started by: nk1984
2 Replies
GMSTRFTIME(3)								 1							     GMSTRFTIME(3)

gmstrftime - Format a GMT/UTC time/date according to locale settings

SYNOPSIS
string gmstrftime (string $format, [int $timestamp = time()]) DESCRIPTION
Behaves the same as strftime(3) except that the time returned is Greenwich Mean Time (GMT). For example, when run in Eastern Standard Time (GMT -0500), the first line below prints "Dec 31 1998 20:00:00", while the second prints "Jan 01 1999 01:00:00". PARAMETERS
o $format - See description in strftime(3). o $timestamp - The optional $timestamp parameter is an integer Unix timestamp that defaults to the current local time if a $timestamp is not given. In other words, it defaults to the value of time(3). RETURN VALUES
Returns a string formatted according to the given format string using the given $timestamp or the current local time if no timestamp is given. Month and weekday names and other language dependent strings respect the current locale set with setlocale(3). EXAMPLES
Example #1 gmstrftime(3) example <?php setlocale(LC_TIME, 'en_US'); echo strftime("%b %d %Y %H:%M:%S", mktime(20, 0, 0, 12, 31, 98)) . " "; echo gmstrftime("%b %d %Y %H:%M:%S", mktime(20, 0, 0, 12, 31, 98)) . " "; ?> SEE ALSO
strftime(3). PHP Documentation Group GMSTRFTIME(3)
All times are GMT -4. The time now is 01:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy