# Need to cut a specific pattern from a line

**URL:** <https://community.unix.com/t/need-to-cut-a-specific-pattern-from-a-line/361340>\
**Category:** Shell Programming and Scripting\
**Created:** [July 10, 2016, 4:00am UTC](https://community.unix.com/t/need-to-cut-a-specific-pattern-from-a-line/361340 "2016-07-10T04:00:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mirwasim](https://community.unix.com/letter_avatar/mirwasim/32/5_5575768a8748004e209b776fc1b2916d.png) [@mirwasim](https://community.unix.com/u/mirwasim)\
**Post date:** [July 10, 2016, 4:00am UTC](https://community.unix.com/t/need-to-cut-a-specific-pattern-from-a-line/361340/1 "2016-07-10T04:00:07Z")

</div>

Hello,  
I need to cut a specific pattern from a line irrespecitve of knowing field place.

I am aware to cut field if you know the place of the field, but for me The sting place varies.

```nohighlight
1468129514436,0,something_error,Non HTTP response code: java.net.URISyntaxException,Non HTTP response message: Illegal character in query at index 81: http://xxx:000/abcd/jsp/soh/fixedinquiries/InquiryFrameSet.jsp?accountSuffix=${SUFFIX_ID}&accountNumber=Number Not Found&domainName=%20&corpUserName=%20&accountId=${ACCOUNT_ID}&pgCode=M&pCode=${PCODE}&imsiNumber=${IMSI_ID}&evisionSTBSerialNo=%20&eccNumber12=%20&arabicDomainName=%20&operation=3&searchPage=SOHACCOUNTIDINQ,Thread Group 1-1,text,false,1226,1,1,0

```

out of above line I am able to get

```nohighlight
cat log.jtl | egrep 'false'| egrep 'http://' | cut -d ',' -f3

```

`False` and `http` will always be there , by above command I get error line and i also get 3rd filed. but i also want to print URL in the error

```nohighlight
something_error http://xxx:000/abcd  

```

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/5_5575768a8748004e209b776fc1b2916d.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [July 10, 2016, 4:40am UTC](https://community.unix.com/t/need-to-cut-a-specific-pattern-from-a-line/361340/2 "2016-07-10T04:40:42Z")

</div>

Not too clear what you really want. Based on what I infer, try

```nohighlight
awk -F, '/false/ && match ($0, /http:\/\/[^\/]*\/[^\/]*/) {print $3, substr ($0, RSTART, RLENGTH)}' file3
something_error http://xxx:000/abcd

```

---

<div class="post-metadata">

**Author:** ![mirwasim](https://community.unix.com/letter_avatar/mirwasim/32/5_5575768a8748004e209b776fc1b2916d.png) [@mirwasim](https://community.unix.com/u/mirwasim)\
**Post date:** [July 10, 2016, 4:53am UTC](https://community.unix.com/t/need-to-cut-a-specific-pattern-from-a-line/361340/3 "2016-07-10T04:53:01Z")

</div>

I got below error.  
I want to print the third field and the the url .  
url is not at specific position every time, it can be at filed 10, 12 13 and so on.  
i want script to pick where ever it is in the line

```nohighlight
awk: syntax error near line 1
awk: bailing out near line 1

```

---

<div class="post-metadata">

**Author:** ![Don\_Cragun](https://community.unix.com/user_avatar/community.unix.com/don_cragun/32/2682_2.png) [@Don\_Cragun](https://community.unix.com/u/Don_Cragun)\
**Post date:** [July 10, 2016, 5:00am UTC](https://community.unix.com/t/need-to-cut-a-specific-pattern-from-a-line/361340/4 "2016-07-10T05:00:33Z")

</div>

> [@mirwasim](#):
>
> I got below error.  
> I want to print the third field and the the url .  
> url is not at specific position every time, it can be at filed 10, 12 13 and so on.  
> i want script to pick where ever it is in the line
> 
> ```plaintext
> awk: syntax error near line 1
> awk: bailing out near line 1
> 
> ```

When using `awk` on Solaris/SunOS systems, change `awk` to `/usr/xpg4/bin/awk` or `nawk` .

---

<div class="post-metadata">

**Author:** ![mirwasim](https://community.unix.com/letter_avatar/mirwasim/32/5_5575768a8748004e209b776fc1b2916d.png) [@mirwasim](https://community.unix.com/u/mirwasim)\
**Post date:** [July 10, 2016, 5:04am UTC](https://community.unix.com/t/need-to-cut-a-specific-pattern-from-a-line/361340/5 "2016-07-10T05:04:10Z")

</div>

Thanks DON, it worked.

I will consider to use [CODE] instead of [ICODE]

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/5_5575768a8748004e209b776fc1b2916d.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [July 10, 2016, 5:04am UTC](https://community.unix.com/t/need-to-cut-a-specific-pattern-from-a-line/361340/6 "2016-07-10T05:04:39Z")

</div>

Again, you're not too eloquent with your request nor error description. Reading between your lines, I guess I recognize the problem. Let me cite

> [@Issue in shell script](https://community.unix.com/t/issue-in-shell-script/357965/6):
>
> If you are using a Solaris/SunOS system, use /usr/xpg4/bin/awk or nawk instead of awk.
