# How to generate a pipe ( | ) delimited file?

**URL:** <https://community.unix.com/t/how-to-generate-a-pipe-delimited-file/215463>\
**Category:** Shell Programming and Scripting\
**Created:** [October 7, 2008, 10:55am UTC](https://community.unix.com/t/how-to-generate-a-pipe-delimited-file/215463 "2008-10-07T10:55:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anushree.a](https://community.unix.com/letter_avatar/anushree.a/32/5_5575768a8748004e209b776fc1b2916d.png) [@anushree.a](https://community.unix.com/u/anushree.a)\
**Post date:** [October 7, 2008, 10:55am UTC](https://community.unix.com/t/how-to-generate-a-pipe-delimited-file/215463/1 "2008-10-07T10:55:02Z")

</div>

:)Hi Friends,

I have certain log files extracted. I want it to be converted in pipe ( | ) delimited file. How do i do it?

E.g.

Account Balance : 123456789 Rs O/P (Account Balance: | 123456789 Rs)  
Account Balance (Last) \> 987654321 Rs O/P (Account Balance (Last) | 987654321 Rs)  
Last update = 21/09/2008 5.30 PM O/P (Last update = | 21/09/2008 | 5.30 | PM)

:eek:Now the real complication is, it can be anything apart from above mentioned example. So it would be great help if you explain the script a bit so that I can write it as I want.

Is it possible?  
If yes,  
Requesting you to guide me to write a "Simple" script.  
Wold appreciate if you explain it briefly as well 😛

Bye  
Anushree

---

<div class="post-metadata">

**Author:** ![unSpawn](https://community.unix.com/letter_avatar/unspawn/32/5_5575768a8748004e209b776fc1b2916d.png) [@unSpawn](https://community.unix.com/u/unSpawn)\
**Post date:** [October 7, 2008, 2:35pm UTC](https://community.unix.com/t/how-to-generate-a-pipe-delimited-file/215463/2 "2008-10-07T14:35:42Z")

</div>

Usually you can use something like 'sed -e "s/[:\>]/|/g" -e "s/=/= |/g" filename' but your "/2008 | 5.30 | PM" can't be anchored since it doesn't follow any replacement rules. Maybe somebody can whip up a better example if you provide more elaborate replacement rules...

---

<div class="post-metadata">

**Author:** ![freelong](https://community.unix.com/letter_avatar/freelong/32/5_5575768a8748004e209b776fc1b2916d.png) [@freelong](https://community.unix.com/u/freelong)\
**Post date:** [October 7, 2008, 3:22pm UTC](https://community.unix.com/t/how-to-generate-a-pipe-delimited-file/215463/3 "2008-10-07T15:22:48Z")

</div>

what's your rules?  
If you do not have rules, nobody can do it.

---

<div class="post-metadata">

**Author:** ![cfajohnson](https://community.unix.com/user_avatar/community.unix.com/cfajohnson/32/16669_2.png) [@cfajohnson](https://community.unix.com/u/cfajohnson)\
**Post date:** [October 7, 2008, 3:28pm UTC](https://community.unix.com/t/how-to-generate-a-pipe-delimited-file/215463/4 "2008-10-07T15:28:26Z")

</div>

How are the fields delimited in the file?

If the separator is any of the :, \>, and =, use awk, with FS set to a pattern that matches all three:

```nohighlight
awk -F '[:>=]' '
   BEGIN { OFS = "|" }
         { $1 = $1; print }
' LOGFILE

```

---

<div class="post-metadata">

**Author:** ![anushree.a](https://community.unix.com/letter_avatar/anushree.a/32/5_5575768a8748004e209b776fc1b2916d.png) [@anushree.a](https://community.unix.com/u/anushree.a)\
**Post date:** [October 15, 2008, 2:21am UTC](https://community.unix.com/t/how-to-generate-a-pipe-delimited-file/215463/5 "2008-10-15T02:21:01Z")

</div>

existing delimiter is "Sapce"

---

<div class="post-metadata">

**Author:** ![agn](https://community.unix.com/letter_avatar/agn/32/5_5575768a8748004e209b776fc1b2916d.png) [@agn](https://community.unix.com/u/agn)\
**Post date:** [October 15, 2008, 2:35am UTC](https://community.unix.com/t/how-to-generate-a-pipe-delimited-file/215463/6 "2008-10-15T02:35:15Z")

</div>

```nohighlight
$ cat buf | tr -s ' ' '|'
Account|Balance|:|123456789|Rs|O/P|(Account|Balance:|123456789|Rs)
Account|Balance|(Last)|>|987654321|Rs|O/P|(Account|Balance|(Last)|987654321|Rs)
Last|update|=|21/09/2008|5.30|PM|O/P|(Last|update|=|21/09/2008|5.30|PM)

```

Is that what you want ?
