我尝试过用 来sed
替换文件中的SELECT
:BELECT
sed 's/SELECT/BELECT/g' add_pixel.sql | diff - add_pixel.sql
给我:
22c22
< BELECT MAX(ID) INTO max_id FROM pixels;
---
> SELECT MAX(ID) INTO max_id FROM pixels;
36c36
< '(BELECT id FROM pixels WHERE pixel_id=''', new_pixel_id,
---
> '(SELECT id FROM pixels WHERE pixel_id=''', new_pixel_id,
47c47
< DELIMITER ;
---
> DELIMITER ;
\ No newline at end of file
这一点已得到证实wc
——后面的字段sed
比原来的字段短一行。
为什么 sed's/SELECT/BELECT/g'
从文件的最后一行删除了换行符?
答案1
您的 sql 文件缺少换行符。sed
“很好”,并确保其输出有一个尾随换行符。
$ diff <(printf 'x') <(printf 'x\n')
1c1
< x
\ No newline at end of file
---
> x
$ diff <(printf 'x\n') <(printf 'x')
1c1
< x
---
> x
\ No newline at end of file
请注意“\ 无换行符...”行是如何根据缺少该行的文件进行定位的。