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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting What does the sed command here exactly doing to csv file?
# 1  
Old 06-04-2017
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.


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

Thank you very much for the helpful info.

Last edited by Scrutinizer; 06-05-2017 at 03:22 AM.. Reason: code tags
# 2  
Old 06-04-2017
Quote:
Originally Posted by 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:

Code:
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.

Last edited by Aia; 06-04-2017 at 08:59 PM.. Reason: Mentions the -i flag
This User Gave Thanks to Aia For This Post:
# 3  
Old 06-05-2017
Quote:
Originally Posted by 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:

Code:
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.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Merge 2 last columns in a csv file using sed or perl

Hello everyone, want to merge 2 last columns 3rd and 4rd (if it exists). I have this 1;2;1;1 2;3;1;1 1;1;2 1;2;3;4 1;1;2 1;2;3;1 Desired output: 1;2;1 1 2;3;1 1 1;1;2 1;2;3 4 1;1;2 1;2;3 1 (3 Replies)
Discussion started by: satir
3 Replies

2. Shell Programming and Scripting

Transposing lines in a csv file with sed

Hi I have a large csv file with lines like below Date,Status,orig,dest,in,out,when,where 2012-01-01 00:30:37,I,48,56,23,98,83,34 2012-06-17 15:00:38,I,72,43,12,65,34,12I will really appreciate if someone can help with a sed script to transpose this to 2012-01-01 00:30:37,I,orig,48... (5 Replies)
Discussion started by: kaf3773
5 Replies

3. Shell Programming and Scripting

Converting txt file into CSV using awk or sed

Hello folks I have a txt file of information about journal articles from different fields. I need to convert this information into a format that is easier for computers to manipulate for some research that I'm doing on how articles are cited. The file has some header information and then details... (8 Replies)
Discussion started by: ksk
8 Replies

4. UNIX for Dummies Questions & Answers

xml to csv using sed and awk command

Hi Guys, Can you help me in creating shell script using sed,awk etc commands to generate csv file using xml file. (5 Replies)
Discussion started by: sbk
5 Replies

5. Shell Programming and Scripting

awk/sed/something else for csv file

Hi, I have a filename.csv in which there are 3 colums, ie: Name ; prefixnumber ; number root ; 020 ; 1234567 user1,2,3 ; 070 ; 7654321 What I want is to merge colum 2 and 3 that it becomes 0201234567 or even better +31201234567 so the country number is used and drop the leading 0.... (9 Replies)
Discussion started by: necron
9 Replies

6. Shell Programming and Scripting

Using awk/sed in handling csv file.

Please study the below script and the output Script: echo "Minimum ${host} ${process} response time=${min} ms" >> ${OUTDIR}/${OUTFILE}; echo "Maximum ${host} ${process} response time=${max} ms" >> ${OUTDIR}/${OUTFILE}; echo "Average ${host} ${process} response time=${avg} ms" >>... (0 Replies)
Discussion started by: ajincoep
0 Replies

7. Shell Programming and Scripting

Parsing complicated CSV file with sed

Yes, there is a great doc out there that discusses parsing csv files with sed, and this topic has been covered before but not enough to answer my question (unix.com forums). I'm trying to parse a CSV file that has optional quotes like the following: "Apple","Apples, are fun",3.60,4.4,"I... (3 Replies)
Discussion started by: analog999
3 Replies

8. Shell Programming and Scripting

Need help with a script to process a CSV file using SED and AWK

I get a CSV file every day with 2 columns and multiple rows ex: date1,date2 ( both the fields are varchar fields) This data has to be updated in a table which is being done manually and i want to automate that. 1. I have to select all the data from the prod table( 2 columns { date1,date2}) into... (4 Replies)
Discussion started by: kkb
4 Replies

9. Shell Programming and Scripting

Remove text from a csv file using sed

I am trying to remove the ita from this file: "1234ita","john","smith" "56789ita","jim","thomas" the command i am using is: sed '/^ita/d' infile.csv > outfile.csv it is running but doing nothing, very rarely use sed so trying to learn it any help would be appreciated (2 Replies)
Discussion started by: Pablo_beezo
2 Replies

10. Shell Programming and Scripting

sed *.csv from file > newfile with /n

I have a an output file with a format: something blah1.csv blah2.csv blah3.csv somethingelse and I'm trying to use sed to pull all the *.csv entries out and put them 1 per line on a new file. I can't quite figure out how to write them to a new file with carriage returns, is there a simple way... (8 Replies)
Discussion started by: unclecameron
8 Replies
Login or Register to Ask a Question