Capturing Data between first quote and next quote


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Capturing Data between first quote and next quote
# 1  
Old 09-26-2008
Capturing Data between first quote and next quote

I have input file like


RDBMS FALIURE UTY8703 'USER_WORK.TEST' .HIghest return code '12'


I want to parse data which comed between first quote till next quote

USER_WORK.TEST


can you please suggest how to do that
# 2  
Old 09-26-2008
Code:
awk ' if (index($0, "'") >0 ) {split($0,arr, "'") ;print arr[2]} else {continue}' file

# 3  
Old 09-26-2008
Hi.

An sed directive with regular expressions can be used, but may be more cryptic:
Code:
#!/bin/bash -

# @(#) s2       Demonstrate extraction of string between left-most markers.

echo
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version "=o" $(_eat $0 $1) sed
set -o nounset
echo

FILE=${1-data1}

echo " Data file $FILE:"
cat $FILE

echo
echo " Results:"
sed -n "s/[^']*'\([^']*\)'.*/\1/p" $FILE

exit 0

Producing:
Code:
% ./s2

(Versions displayed with local utility "version")
Linux 2.6.11-x1
GNU bash 2.05b.0
GNU sed version 4.1.2

 Data file data1:
RDBMS FALIURE UTY8703 'USER_WORK.TEST' .HIghest return code '12'

 Results:
USER_WORK.TEST

See man sed for details ... cheers, drl
# 4  
Old 09-26-2008
Code:
using awk:
 
echo "RDBMS FALIURE UTY8703 'USER_WORK.TEST' .HIghest return code '12'" | awk -F"'" '{print $2}'
 
using cut:
 
echo "RDBMS FALIURE UTY8703 'USER_WORK.TEST' .HIghest return code '12'" | cut -d"'" -f2

# 5  
Old 09-26-2008
if you have Python:
Code:
#!/usr/bin/env python
for line in open("file"):
    start=line.index("'") #check for position of first quote
    end=line[start+1:].index("'") # check for position of second quote
    print line[start+1:start+end] #get value

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing all but the first and last double quote in a line with a single quote with awk

From: 1,2,3,4,5,This is a test 6,7,8,9,0,"This, is a test" 1,9,2,8,3,"This is a ""test""" 4,7,3,1,8,"""" To: 1,2,3,4,5,This is a test 6,7,8,9,0,"This; is a test" 1,9,2,8,3,"This is a ''test''" 4,7,3,1,8,"''"Is there an easy syntax I'm overlooking? There will always be an odd number... (5 Replies)
Discussion started by: Michael Stora
5 Replies

2. Shell Programming and Scripting

Replacing Double Quote in Double Quote incsv file

Hi All , We have source data file as csv file and since data could contain commas ,each attribute is quoted into double quotes.However problem is that some of the attributa data also contain double quotes which is converted to double double quote while creating csv file XLs data : ... (2 Replies)
Discussion started by: Shalini Badal
2 Replies

3. UNIX for Dummies Questions & Answers

To quote or not

My question is, "Do I not understand, or is my information out of date?" I am trying to just be a student, rtfm'ing. I am working on my work systems. Is it simply that the book was printed in 2002 and a lot has changed since then, or did I miss something? Working in Korn Shell. I have been... (5 Replies)
Discussion started by: g.j.huebschman
5 Replies

4. Shell Programming and Scripting

getting value between double quote

Can somebody supply me with a simple way to get a value between two double quotes? Example: input = ADR base is "/u01/app/oracle" output = /u01/app/oracle Thanks to all who answer (4 Replies)
Discussion started by: BeefStu
4 Replies

5. Shell Programming and Scripting

Processing data that contains space and quote delimiters

I need to write a Bash script to process a data file that is in this format: 1 A B C D E 2 F G "H H" I J As you can see, the data is delimited by a space, but there are also some fields that contain spaces and are surrounded by double-quotes. An example of that is "H H". I wrote... (7 Replies)
Discussion started by: RickS
7 Replies

6. Shell Programming and Scripting

replacing a quote in some lines with multiple quote fields

i want to replace mistaken quotes in line starting with tag 300 and relocate the quote in the correct position so the input is 223;25 224;20100428064823;1;0;0;0;0;0;0;0;8;1;3;9697;18744;;;;;;;;;;;; 300;X;Event:... (3 Replies)
Discussion started by: wradwan
3 Replies

7. Shell Programming and Scripting

Regex in grep to match all lines ending with a double quote (") OR a single quote (')

Hi, I've been trying to write a regex to use in egrep (in a shell script) that'll fetch the names of all the files that match a particular pattern. I expect to match the following line in a file: Name = "abc" The regex I'm using to match the same is: egrep -l '(^) *= *" ** *"$' /PATH_TO_SEARCH... (6 Replies)
Discussion started by: NanJ
6 Replies

8. Shell Programming and Scripting

double-quote inside double-quote

hey all, i made a simple .sh like this: echo "<style media="screen" type="text/css">@import url("main.css");</style>" but the output is: <style media=screen type=text/css>@import url(main.css);</style> i want to keep double-quotes, can anyone help me? thanks (3 Replies)
Discussion started by: indraf
3 Replies

9. Shell Programming and Scripting

single quote

Hi I have a shell script with many lines as below: comment on column dcases.proj_seq_num is dcases_1sq; .... .... I want the above script to be as below: comment on column dcases.proj_seq_num is 'dcases_1sq'; I want to have single quotes like that as above for the entire shell... (2 Replies)
Discussion started by: dreams5617
2 Replies

10. Shell Programming and Scripting

Don't Quote Me On This...

Korn Shell Scripting on Solaris 9 Hello, this is my first post, I figure I share a problem and how I fixed it as well as ask a question that I'm currently stuck on. A version of "Give a Penny" "Take a Penny" First Problem - I'm currently writing an automated version of one of the two types... (3 Replies)
Discussion started by: Janus
3 Replies
Login or Register to Ask a Question