# What does the sed command here exactly doing to csv file?

**URL:** <https://community.unix.com/t/what-does-the-sed-command-here-exactly-doing-to-csv-file/366896>\
**Category:** Shell Programming and Scripting\
**Created:** [June 4, 2017, 4:51pm UTC](https://community.unix.com/t/what-does-the-sed-command-here-exactly-doing-to-csv-file/366896 "2017-06-04T16:51:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cplusplus1](https://community.unix.com/letter_avatar/cplusplus1/32/6_449c533f586939b6e5f246632a46421f.png) [@cplusplus1](https://community.unix.com/u/cplusplus1)\
**Post date:** [June 4, 2017, 4:51pm UTC](https://community.unix.com/t/what-does-the-sed-command-here-exactly-doing-to-csv-file/366896/1 "2017-06-04T16:51:22Z")

</div>

I have the following csv file at the path; now using sed command. what is this exactly doing.

```nohighlight
sed -i 's/[\t]/,/g' /FTP/LAB_RESULT_CM.csv

```

Thank you very much for the helpful info.

---

<div class="post-metadata">

**Author:** ![Aia](https://community.unix.com/user_avatar/community.unix.com/aia/32/917_2.png) [@Aia](https://community.unix.com/u/Aia)\
**Post date:** [June 4, 2017, 7:52pm UTC](https://community.unix.com/t/what-does-the-sed-command-here-exactly-doing-to-csv-file/366896/2 "2017-06-04T19:52:59Z")

</div>

> [@cplusplus1](#):
>
> I have the following csv file at the path; now using sed command. what is this exactly doing.
> 
> sed -i 's/[\t]/,/g' /FTP/LAB\_RESULT\_CM.csv
> 
> Thank you very much for the helpful info.

Most likely is trying to replace any tab for a coma.  
However, in POSIX the RE bracket expression `[\t]` would try to match a literal `back slash` or a `t` character.  
In any case there's no advantage to use it there:

```plaintext
sed -i 's/\t/,/g' /FTP/LAB_RESULT_CM.csv

```

The -i is replacing the original `LAB_RESULT_CM.csv` file with the result of the execution.

---

<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:** [June 5, 2017, 3:47am UTC](https://community.unix.com/t/what-does-the-sed-command-here-exactly-doing-to-csv-file/366896/3 "2017-06-05T03:47:12Z")

</div>

> [@aia](#):
>
> Most likely is trying to replace any tab for a coma.  
> However, in POSIX the RE bracket expression `[\t]` would try to match a literal `back slash` or a `t` character.  
> In any case there's no advantage to use it there:
> 
> ```plaintext
> sed -i 's/\t/,/g' /FTP/LAB_RESULT_CM.csv
> 
> ```
> 
> The -i is replacing the original `LAB_RESULT_CM.csv` file with the result of the execution.

As Aia said, the BRE ` [\t]` will match a single \<backslash\> or lower-case letter \<t\> and the substitute command `s/[\t]/,/g` will replace each occurrence of either of those characters with a \<comma\>. But the POSIX BRE `\t` does not match a \<tab\> character; it matches exactly the same thing matched by the BRE `t` (i.e., just a lower-case letter \<t\>.

Some versions of `sed` , when not forced to operate in POSIX conforming mode, treat some backslash escapes in BREs as special and do recognize `\n` as a \<newline\> character, `\t` as a \<tab\> character, `\b` as a \<backspace\> character, `\r` as a \<carriage-return\> character, and `\a` as an alert (AKA \<BEL\>) character.

Since you haven't told us what operating system or version of `sed` you're using, we can't tell you which of several possible behaviors might occur on your system.

Similarly, the `sed -i` option is an extension to the standards. On some systems it will give you a syntax error for an unknown option. On some other systems it will perform in-place edits on the files named as operands (sometimes also creating a backup file if `-i` is given an option-argument. And on some other systems it might use case-insensitive matches when matching strings using REs.

The above differences between implementations are examples of why it is always a good idea to tell us what operating system, shell, and versions of tools you are using when you post a question like this.
