1

I have a file which contains below data

7[label = "ScanStep: T_b0\n(T.a = 1)\na\nb\nc\nd\ne\ndob\ntimestamp1\nUnc: Integer(8)\nUnc: Integer(8)\nUnc: Varchar(80)\nUnc: Numeric(10,2)\nUnc: Varbinary(80)\nUnc: Date(8)\nUnc: Timestamp(8)", color = "brown", shape = "box"];

7[label = "ScanStep: cde_b1\nBuddies: (cde_b1, cde_b0, cde_b2)\n(public.cde.newcol = \'013\')\nssn\nnewcol\nmasked_ssn\nUnc: Numeric(10,2)\nUnc: Varbinary(80)\nUnc: Date(8)\nUnc: Timestamp(8)", color = "brown", shape = "box"];

there are multiple such entries.

I need to print only those entries which comes after "\n(" and before ")\n".

I have tried with awk but unable to provide delimiter.

awk -F "\\n\\\\(" '{print $1}' unset

prints whole line of the file

awk -F "\\n\\(" '{print $1}' unset

prints awk: warning: escape sequence \(' treated as plain(' awk: fatal: Unmatched ( or (: / (/

1

You can accomplish this with sed like so:

sed -e 's,\\n(.*,,' unset

or with awk you have to do a lot of escaping

awk -F'\\\\n\\(' '{print $1}' unset

to get the right escaping for both the \ before the n and to protect against the special interpretation of the (

  • Thanks Eric. It worked and m using this one as awk is bit fast as compare to sed and other stuffs. – anurag Jun 24 '16 at 3:21
1

I used a combination of grep and sed to accomplish your goal of after \n( and before )\n

grep -o '\\n(.*)\\n' test.txt|sed -e 's/\\n//g'

Sample output

(T.a = 1)
(public.cde.newcol = \'013\')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.