1

Extract the value for OWNER in the following:

{{USERID 9898}}{{OWNER Wayne, Daniel}}{{EMAIL [email protected]}}

To get this string I am using grep on a text file. In all other cases only one value is contained on each line, so they are not an issue. My problem is removing the text after OWNER but before the }} brackets, leaving me with only the string 'Wayne, Daniel'.

So far I have began looking into writing a for loop to go through the text a character at a time, but I feel there is a more elegant solution then my limited knowledge of unix.

4 Answers 4

3

With grep

> cat file
{{USERID 9898}}{{OWNER Wayne, Daniel}}{{EMAIL [email protected]}}

> grep -Po '(?<=OWNER )[\w, ]*' file
Wayne, Daniel
Sign up to request clarification or add additional context in comments.

Comments

3

Try cat file.txt | perl -n -e'/OWNER ([^\}]+)/ && print $1'

2 Comments

returns a single quote. I haven't used perl yet, I will look into that.
If there are multiple matches, this will concatenate them. Also cat is not required here.
3

You can use this awk:

awk -F '{{|}}' '{sub(/OWNER +/, "", $4); print $4}' file
Wayne, Daniel

Comments

1

Try this. I use cut

INPUT="{{USERID 9898}}{{OWNER Wayne, Daniel}}{{EMAIL [email protected]}}"
SUBSTRING=`echo $INPUT| cut -d' ' -f3`
SUBSTRING2=`echo $INPUT| cut -d',' -f2`
SUBSTRING2=`echo $SUBSTRING2| cut -d'}' -f1`
echo $SUBSTRING$SUBSTRING2

maybe is not the most elegant way but works.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.