What is the ^I character and how do I find it with sed?
Solution 1
You already have an answer for what the ^Is are, but one reason your second sed
command fails is that you're using the wrong sequence for matching a tab. The sequence that matches a tab is \t
, not \\t
. \\t
matches a \
followed by a t
.
Solution 2
^ is normally shorthand for Ctrl and Ctrl-I is the same as Tab
Related videos on Youtube
![Richard Herron](https://i.stack.imgur.com/YnrVD.png?s=256&g=1)
Richard Herron
Updated on September 18, 2022Comments
-
Richard Herron almost 2 years
I usually import data from csv files to MySQL, but my data provider leaves NULL entries as "", so I need to replace "" with "\N". This is easy enough with a script like
for csvfile in *.csv do sed -i -e 's/^,/\\N,/' -e 's/,$/,\\N/' -e 's/,,/,\\N,/g' -e 's/,,/,\\N,/g' $csvfile done
However, I have a csv file with commas, so the import fails. I got the file as "tab delimited" and tried
for txtfile in *.txt do sed -i -e 's/^\\t/\\N\\t/' -e 's/\\t$/\\t\\N/' -e 's/\\t\\t/\\t\\N\\t/g' -e 's/\\t\\t/\\t\\N\\t/g' $txtfile done
But it still fails (as far as I can tell, the script doesn't add any "\N"). When I open the tab-delimited file in Vim and type
:set list
it looks like tabs are stored instead as "^I". I tried replacing "\t" with "\^I", but doesn't add the "\N" NULL characters that I need.Any ideas? Thanks!
-
Richard Herron about 13 yearsDo you know how I can make my
sed
work? I tried replacing "\\t" with "\^I" but it didn't work? -
Richard Herron about 13 yearsMakes sense. I am confusing wanting an explicit "\N", which I add with "\\N", with looking for the tab. Thanks!