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

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:

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.

1 Like

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.

1 Like