Terminate left side portion of a string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Terminate left side portion of a string
# 1  
Old 05-03-2012
Terminate left side portion of a string

I have a awk file which consists of the follwoing code in file select.awk :
Code:
/xxx/ {
        time = gensub(/xxx \*\*\*(.*)/, "\\1", "g")
        printf("%s\n",time)
        next
}

and an input file with the following file file.txt :-

HTML Code:
xxx ***Wed May 2 18:00:00 CDT 2012
AAA AAAA AAAA xxx ***Wed May 2 18:00:05 CDT 2012
AA xxx ***Wed May 2 18:00:10 CDT 2012
xxx ***Wed May 2 18:00:15 CDT 2012
0.00          0.00xxx ***Wed May 2 18:00:20 CDT 2012
when i execute it like this . it shows below o/p:-
Code:
sed -n "p" file.txt | awk -f select.awk

gives me

Code:
Wed May 2 18:00:00 CDT 2012
AAA AAAA AAAAWed May 2 18:00:05 CDT 2012
AAWed May 2 18:00:10 CDT 2012
Wed May 2 18:00:15 CDT 2012
0.00          0.00xxx ***Wed May 2 18:00:20 CDT 2012


I am trying to delete the left part of the string which comes after xxx *** and including xxx ***.

O/p should be only the data format in every line rest all should be eliminated but as the current code uses replace for xxx *** it only erases those but no the left part of it .

Code:
Wed May 2 18:00:00 CDT 2012
Wed May 2 18:00:05 CDT 2012
wed May 2 18:00:10 CDT 2012
Wed May 2 18:00:15 CDT 2012
Wed May 2 18:00:20 CDT 2012

can someone tell me how can i do that

Moderator's Comments:
Mod Comment Welcome to the UNIX and Linux Forums. Please use [code][/code] tags. Video tutorial on how to use them

Last edited by Scrutinizer; 05-03-2012 at 02:40 AM.. Reason: mistakes - mod: Some more code tags...
# 2  
Old 05-03-2012
with sed

Code:
sed 's/.*\*\*\*\(.*\)/\1/g' filename.txt

---------- Post updated at 01:41 PM ---------- Previous update was at 01:39 PM ----------

with awk

Code:
 awk -vFS="\*\*\*" '{print $2}' filename.txt

# 3  
Old 05-03-2012
This works but I am looking to use a string manipulation function to get this done.


Code:
/xxx/ {         time = gensub(/xxx \*\*\*(.*)/, "\\1", "g")         printf("%s\n",time)         next }

As gensub is not working for me can you help me out how to use a split function or substr function to get the same results .

Last edited by shikshavarma; 05-03-2012 at 09:56 PM.. Reason: code tags missing
# 4  
Old 05-03-2012
Try this:

Code:
/xxx/ { gsub(/^.*xxx \*\*\*/, "",$0); print }

This User Gave Thanks to Chubler_XL For This Post:
# 5  
Old 05-03-2012
Thank's a lot .that's all i was looking for it rocks now.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Matching number of syllables on right-hand and left side

I am developing a database for translating names. I have mapped through a rule engine syllables in English to syllables in Indic, delimited by an equal to sign. An example will illustrate this ra m=रा म ku ma r=कु मा र mo=मो la l=ला ल gi ta=गी ता ka la va ti=कa ला वa ती However it so... (3 Replies)
Discussion started by: gimley
3 Replies

2. Shell Programming and Scripting

Get portion of string from the end

Hi all, Can anyone suggest a way to get a portion of string from the end? So: $ORACLE_SID=blt10cr1 We can drop the final '1' and end up with: $ORACLE_SID=blt10cr So far I have the following: echo $ORACLE_SID | cut -c1-5 and echo $ORACLE_SID | cut -c1-6 | rev any ideas? (4 Replies)
Discussion started by: jonnyd
4 Replies

3. Shell Programming and Scripting

How to extract portion of a string?

Hi Gurus, Would like to seek some help on how to extract a portion of string from log's output as shown below. Sample of raw data: piece handle=/test123/disk_dump/test123/df0_cntrl_PCPFCI20120404_68498 tag=TAG20120404T180035 comment=NONE piece... (13 Replies)
Discussion started by: superHonda123
13 Replies

4. Shell Programming and Scripting

Remove first portion of string

I have a script which currently uses a file containing a list of directories as an argument. The file is read in to an array, and then the array is iterated in a for loop. What I would like to do is cut off the first few directories of the directory path (they won't exist on the server where the... (5 Replies)
Discussion started by: msarro
5 Replies

5. Shell Programming and Scripting

Extracting a portion of the string and comparing

I have 2 text files say file1.txt and file2.txt . Some of the sample records for file1.txt were shown below: XXXXX12345XXXXXXX12 3456789YYYYY XXXXXXXXXX12345XX123457485YYYYY XX12345XXXXXXXXXX123454658YYYYY for file2.txt, some of the sample records were shown below: ... (5 Replies)
Discussion started by: bobby1015
5 Replies

6. Shell Programming and Scripting

Help on extracting portion of string

Hi Gurus, I've some sample of my log information as shown below. -> Processing ABCD123456 This is tp version 372.04.57 (release 700, unicode enabled) This is R3trans version 6.14 (release 700 - 05.03.09 - 08:28:00). unicode enabled version R3trans finished (0000). Warning: Parameter... (1 Reply)
Discussion started by: superHonda123
1 Replies

7. Shell Programming and Scripting

extract string portion using sed

Hi All I have 3 files as listed below and highlighted in bold the portions of the filenames I need to extract: TOS_TABIN218_20090323.200903231830 TOS_TABIN219_1_20090323.200903231830 TOS_TABIN219_2_20090323.200903231830 I tried source_tabin_name=`echo $fname | sed 's/_.*//'` but I... (6 Replies)
Discussion started by: santam
6 Replies

8. UNIX for Dummies Questions & Answers

Stripping a portion of string from behind!!!

Hi, How to strip a portion of a file name from behind...Say for Eg..i have a file name like aaaaa.bbbbb.Mar-17-2007 i want to remove .Mar-17-2007...is there a one line command which can give this output... Thanks Kumar (5 Replies)
Discussion started by: kumarsaravana_s
5 Replies

9. Shell Programming and Scripting

How to get the most left hand string ??

Hi, I remember once seeing a way to get the left most string in a word. Let's say: a="First.Second.Third" (separated by dot) echo ${a#*.} shows --> Second.Third echo ${a##*.} shows --> Third How do I get the the left most string "First" Or "First.Second" ??? Tried to replace #... (2 Replies)
Discussion started by: jfortes
2 Replies

10. UNIX for Dummies Questions & Answers

How to extract a portion of a string from the whole string

How to extract a portion of a string from a full string using unix. For example: Say source string is = "req92374923.log" I want only the numeric portion of the string say "92374923" how to do that in Unix. (2 Replies)
Discussion started by: ds_sastry
2 Replies
Login or Register to Ask a Question