# How to append string checking other same string?

**URL:** <https://community.unix.com/t/how-to-append-string-checking-other-same-string/324344>\
**Category:** Shell Programming and Scripting\
**Created:** [February 14, 2013, 11:14am UTC](https://community.unix.com/t/how-to-append-string-checking-other-same-string/324344 "2013-02-14T11:14:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jagdishrout](https://community.unix.com/user_avatar/community.unix.com/jagdishrout/32/8105_2.png) [@jagdishrout](https://community.unix.com/u/jagdishrout)\
**Post date:** [February 14, 2013, 11:14am UTC](https://community.unix.com/t/how-to-append-string-checking-other-same-string/324344/1 "2013-02-14T11:14:18Z")

</div>

Hi ,  
I have a file like

```nohighlight
A-0044150|ABC/Frito/
A-0044150|GFHU
A-0150075|Bud Racing
A-0187811|Bud Light
A-0187811|RW&B signmaking

```

I Want the o/p like

```auto
A-0044150|ABC/Frito/,GFHU
A-0150075|Bud Racing
A-0187811|Bud Light,RW&B signmaking

```

---

<div class="post-metadata">

**Author:** ![Yoda](https://community.unix.com/user_avatar/community.unix.com/yoda/32/2498_2.png) [@Yoda](https://community.unix.com/u/Yoda)\
**Post date:** [February 14, 2013, 11:26am UTC](https://community.unix.com/t/how-to-append-string-checking-other-same-string/324344/2 "2013-02-14T11:26:21Z")

</div>

```nohighlight
awk -F\| ' NR==1 {
        printf "%s", $0;
        p = $1;
} p == $1 {
        printf ",%s", $2;
} p != $1 {
        printf "\n%s", $0;
} {
        p = $1;
} END {
        printf "\n";
}' file

```

---

<div class="post-metadata">

**Author:** ![vbe](https://community.unix.com/user_avatar/community.unix.com/vbe/32/266_2.png) [@vbe](https://community.unix.com/u/vbe)\
**Post date:** [February 14, 2013, 11:39am UTC](https://community.unix.com/t/how-to-append-string-checking-other-same-string/324344/3 "2013-02-14T11:39:37Z")

</div>

I was tempted to ask what you tried so far ...  
Next time I will!!  
This forum is to help members to solve NOT do their work... remember?  
We are expecting to see a minimum of effort like what you tried so far...  
And this question ressembles furiously at this one you asked previously:

> **[How to append a string by comparing another string?](https://www.unix.com/shell-programming-and-scripting/216010-how-append-string-comparing-another-string.html)**
>
> Hi , I have one file like pre { overflow:scroll; margin:2px; padding:15px; border:3px inset; margin-right:10px; } Code: BUD,BDL BUDCAR BUD,BDL BUDLAMP ABC,CDF,KLT ABISKAR ABC,CDF,KLT CORNEL ABC,CDF,KL | The UNIX and Linux Forums

So thread closed!  
I shall close the next thread I see from you if its just asking for us to do your work, you have been warned.
