Extract string between two different characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract string between two different characters
# 8  
Old 05-07-2008
I need to handle the following line:

Code:
192.168.0.0 - - [07/May/2008:11:42:31 +0100] "GET /images/top_line.gif HTTP/1.1" 200 51 "https://server.com/caches/themes/html/styles/All.css" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14 WHE_SLS" "sbslang=; www-stats=11984687e55.1dd9a88; PD_STATEFUL_d796f17c-15c0-11dd-bb1e-c0a8580aaa77=%2Fwas; JSESSIONID=0000sSm-zPjR_Wd9ZG4yYwMBx7U:12cgh2sq9; sbsmwwindowlist.AGY=%5B%5B%2269848949%22%2C%220%22%2C%22default%22%2C%220%22%2C%221%22%2C%2207114231051%22%2C%220%22%2C%221280%22%2C%22AGY%22%2C%22%22%5D%5D"

and extract the part marked in bold letters.
# 9  
Old 05-07-2008
Assuming the format is constant:

Code:
awk -F";" '{sub(".*:","",$8);print $8}'

Regards
# 10  
Old 05-07-2008
Unfortunately the format is not constant, the position of the JSESSIONID parameter varies.
# 11  
Old 05-07-2008
Use nawk or /usr/xpg4/bin/awk on Solaris.

Code:
awk 'NF>1&&$0=$2' FS="JSESSIONID=[^:]*:" RS=";" input

Code:
perl -lne'print $1 while /JSESSIONID=.*?:(.*?);/g' input

# 12  
Old 05-07-2008
Ok, thanks! Both work.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Outputting characters after a given string and reporting the characters in the row below --sed

I have this fastq file: @M04961:22:000000000-B5VGJ:1:1101:9280:7106 1:N:0:86 GGGGGGGGGGGGCATGAAAACATACAAACCGTCTTTCCAGAAATTGTTCCAAGTATCGGCAACAGCTTTATCAATACCATGAAAAATATCAACCACACCA +test-1 GGGGGGGGGGGGGGGGGCCGGGGGFF,EDFFGEDFG,@DGGCGGEGGG7DCGGGF68CGFFFGGGG@CGDGFFDFEFEFF:30CGAFFDFEFF8CAF;;8... (10 Replies)
Discussion started by: Xterra
10 Replies

2. UNIX for Beginners Questions & Answers

Extract characters from a string name

Hi All, I am trying to extract only characters from a string value eg: abcdedg1234.cnf How can I extract only characters abcdedg and assign to a variable. Please help. Thanks (2 Replies)
Discussion started by: abhi_123
2 Replies

3. UNIX for Dummies Questions & Answers

Extract string between two special characters

Hi, I have a file that looks something like >1-18*anc... (12 Replies)
Discussion started by: jyu429
12 Replies

4. Shell Programming and Scripting

Search String and extract few lines under the searched string

Need Assistance in shell programming... I have a huge file which has multiple stations and i wanted to search particular station and extract few lines from it and the rest is not needed Bold letters are the stations . The whole file has multiple stations . Below example i wanted to search... (4 Replies)
Discussion started by: ajayram_arya
4 Replies

5. Shell Programming and Scripting

Extract string between 2 special characters

Hi, I have a unix file with contents as below Line1: ABC MNN X$$QWERTY$$ JKL Line2: HELLO $$HOW$$ ARE $$YOU$$ DOING i want to extract the string between $$ and $$ ie i want the output as QWERTY HOW YOU i want those strings seperated by some character say | desired output is... (7 Replies)
Discussion started by: vinredmac
7 Replies

6. Shell Programming and Scripting

to extract string from main string and string comparison

continuing from my previous post, whose link is given below as a reference https://www.unix.com/shell-programming-scripting/171076-shell-scripting.html#post302573569 consider there is create table commands in a file for eg: CREATE TABLE `Blahblahblah` ( `id` int(11) NOT NULL... (2 Replies)
Discussion started by: vivek d r
2 Replies

7. Shell Programming and Scripting

remove characters from string based on occurrence of a string

Hello Folks.. I need your help .. here the example of my problem..i know its easy..i don't all the commands in unix to do this especiallly sed...here my string.. dwc2_dfg_ajja_dfhhj_vw_dec2_dfgh_dwq desired output is.. dwc2_dfg_ajja_dfhhj it's a simple task with tail... (5 Replies)
Discussion started by: victor369
5 Replies

8. Shell Programming and Scripting

help with Scripting - trying to search for string and extract next few characters

Hi I am new to world on unix scripting so any assistance would be gratefully appreciated, I am trying to write a script which reads through a file, reads in line by line, searches for a pattern, copies string after it and then to do a search and replace elsehwere in the line, so the... (7 Replies)
Discussion started by: LonJ_80
7 Replies

9. Shell Programming and Scripting

Extract upper case characters from a string

Hi Friends, I have a script which returns me the following values line by line ora_smon_RCAT102 oracleKHP102B (DESC oraclePROOIDDB92 (DES oraclePMS (DESCRIP oracleBRIO (LOCAL=N oracleBRIO (LOCAL=N oraclePRDB92 (DES oracleBRIO (LOCAL=N oracleBRIO (LOCAL=N oraclePMS (DESCRIP... (4 Replies)
Discussion started by: orakhan
4 Replies

10. Shell Programming and Scripting

Search for string in a file and extract another string to a variable

Hi, guys. I have one question: I need to search for a string in a file, and then extract another string from the file and assign it to a variable. For example: the contents of the file (group) is below: ... ftp:x:23: mail:x:34 ... testing:x:2001 sales:x:2002 development:x:2003 ...... (6 Replies)
Discussion started by: daikeyang
6 Replies
Login or Register to Ask a Question