How-To Extract specific data from a file.

data.txt has several information like the below..

<SERVER>:WEB:MYDOM01:/tmp/cong/MYDOM01,/tmp/app/MYDOM01
<WEBER>:CANES:https-web01,https-web02:/web/apps/https-web01/config

<SERVER>:WEB:MYDOM07:/tmp/cong/MYDOM07,/tmp/app/MYDOM07
<WEBER>:CANES:https-web06,https-web07:/web/apps/https-web07/config
.......
......

I need to read data.txt and pull out all physical paths like the below.

/tmp/cong/MYDOM01
/tmp/app/MYDOM01
/web/apps/https-web01/config
/tmp/cong/MYDOM07
/tmp/app/MYDOM07
/web/apps/https-web07/config

Need a quick way to achieve this same.

awk -v RS="[:,\n]" '/^\//' inputfile

Use nawk on solaris.

i get the below error:

awk -v RS="[:,\n]" '/^\//' data.txt
awk: syntax error near line 1
awk: bailing out near line 1

bash-3.2$ uname -a
SunOS mymac 5.10 Generic_150400-26 sun4v sparc sun4v

Use nawk on solaris.

I used nawk but i dont see anything in the output. It's blank.

OK, you have an old awful awk which doesn't support regexes in the field separator.

How about:

tr ':,' '\n\n' < inputfile | grep '^/'
1 Like

Works good !! Thank you Corona :slight_smile:

1 Like

Another alternative:

perl -nle 'while(/((?:\/[\w-]+)+)/g){print $1}' mohtashims.file

Output:

/tmp/cong/MYDOM01
/tmp/app/MYDOM01
/web/apps/https-web01/config
/tmp/cong/MYDOM07
/tmp/app/MYDOM07
/web/apps/https-web07/config