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
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
awk ' if (index($0, "'") >0 ) {split($0,arr, "'") ;print arr[2]} else {continue}' file
Hi.
An sed directive with regular expressions can be used, but may be more cryptic:
#!/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:
% ./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
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
if you have Python:
#!/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