Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

MySQL command I have so far:

 load data infile 'data.txt' into table foo (column_foobar);

data.txt:

    bar1
    bar2
    bar3

Note the tab at beginning of each line. How can I ignore the tab with MySQL so that bar1, bar2, bar3 gets loaded in column_foobar?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

You may be able to use the LINES STARTING BY clause

load data infile 'data.txt' into table foo LINES STARTING BY '\t'  (foobar);

which will do what you want for that data provided. If your data was for example

bar1
bar2
bar3    bar4

with a tab between bar3 and bar4 then you would have to use something like

load data infile 'data.txt' into table foo 
FIELDS TERMINATED BY '\n'
LINES STARTING BY '\t'  (foobar);
share|improve this answer
    
Very good answer. As it turns out I hadn't tabs in my data.txt file, but four spaces, so I ended up using four phyiscal spaces instead of the \t, which worked great! –  Achmed Durangi Nov 7 '12 at 13:41

Can't you just remove the leading tabs with sed 's/^<tab goes here>//' before loading the file?

If you (in bash) push Ctrl+V and then TAB, you will get a tab in the shell that sed can remove.

share|improve this answer
    
That would add one more step in processing my files. So I prefer lain's solution. –  Achmed Durangi Nov 7 '12 at 14:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.