sed ã§ã¿ãã®åé€ã眮æãããããã話ã§ãã
ã¯ããã«
ãã¿ãŒããã«äžã§ã¿ããå ¥åãããããšããæ¹
^V
ã®ããšã« <tab>
ã§å
¥åã§ããŸããïŒç°å¢ã«ããããïŒ
ãsed ã³ãã³ãã§ã¿ãã眮æãããããšããæ¹
以äžã®æ¹æ³ãªã©ããããŸãã
# å é ã®ã¿ sed s/$'\t'// # ãã¹ãŠ => tr -d '\t' ã®æ¹ããããã sed s/$'\t'//g
ãsed ã«ã€ããŠã¡ãã£ãšç¥ã£ãŠãããããªãããšããæ¹ã¯èšäºã®ç¶ããã©ããã
ãã ãèªãåã«ã¿ãŒããã«ã§ãã¹ã¯ãªããã§ãæ§ããŸããã以äžã®ã³ãã³ããå®è¡ããŠã¿ãŠãã ãããïŒç°å¢ã«ãã£ãŠéããããããŸãããïŒæåŸã ãããã¯ã¹ã©ãã·ã¥ã2ã€ã«ãªã£ãŠããšæããŸããsed ã䜿ãå Žåãããçµæ§éèŠã§ãã
set -- \\\\ "\\\\" $'\\\\' '\\\\' echo $@
以äžã§ BSD sed ã«é¢ããŠè²ã æžããŠãŸããããããš sed ã®ã³ãã³ãéšåå šäœãã¯ãªãŒãã§æ¬ã£ãŠããªãã£ããããŸãããäœæ ããã«ã¯ãªãŒããå¿ èŠãïŒããèããŠããã ããšé¢çœããããããŸããã
ãªããåããã«è²ã æžããŠããã©è¶£å³ã§äœ¿ã£ãŠãã¬ãã«ãªã®ã§è©³ããããšã¯æžç±ãšãèªãã§ã¿ãŠãã ããã
sed ã§ã¿ãæåã眮æãã
ãã£ãšæ€çŽ¢ã§æ¥ãããæ¹ã¯ä»¥äžã®ãããªã³ãã³ããå®è¡ããŠãã¿ããæ¶ããªãããããã¯ãã¿ãã§ã¯ãªã t ãæ¶ããããšãã人ãå€ããšæããŸãã
sed 's/\t//'
Mac OS X ãªã©ã«å
¥ã£ãŠãã BSD sed 㯠echo ã printf ã®ããã«ã¹ã¯ãªããäžã® \t
ãã¿ãã«ã¯å±éããŸããã
ãã®çç±ã¯ãã£ãšä»¥äžã®ã³ãã³ã㧠t
ãåé€ã§ããããâŠâŠâŠãããããŸããã
sed 'st\tttg'
\t
ãã¿ãæåãšããŠæ±ããã©ããã¯ã³ãã³ãã«ãã£ãŠç°ãªããŸããBSD sed ã¯ãã¿ãæåãšããŠæ±ããªããæ¹ã§ãããã¿ãæåã䜿çšã§ããªãããã§ã¯ãããŸãããBSD sed ã§ã¿ãæåãæ±ãå Žåã¯äºã \t
ã âïŒã¿ãïŒãšããŠå±éããŠãããŸããããã¹ããšãã£ã¿ãªã©ã§ã¿ãæåãçŽæ¥å
¥åããŠãããŸããŸããããã¿ããªã®ãã¹ããŒã¹ãªã®ãå€å¥ãé£ããªã£ãããããã¹ãæŽåœ¢æã«å€æãããŠããŸãå¯èœæ§ãããã®ã§ããŸãããããããŸããã
ãããã©ããã£ãŠæžãã®ãïŒãšããããšã«ãªããŸããããã§ã¯ã·ã§ã«ã® $'\t'
ã䜿ããŸãã
以äžã®ïŒã€ã®æžãæ¹ã¯ã©ã¡ããã¿ãæåãåé€ããŸããäžæ®µã§ã¯ãããã³ã°éšå㧠$''
å±éãè¡ããäžæ®µã§ã¯ sed ã¹ã¯ãªããå
šäœã§ $''
å±éãè¡ããŸããããã¯ã·ã§ã«ã®æ©èœã§ãã£ãŠ sed ã®æ©èœã§ã¯ãããŸãããïŒäžéšã®ã·ã§ã«ã§ã¯ $'\t'
ããã®ãŸãŸ $'\t'
ãšããŠåºåããŸãã®ã§æ³šæããŠãã ããã
sed s/$'\t'// sed $'s/\t//'
ã©ã®ãããªã¹ã¯ãªããã sed ã«æž¡ãããŠããã㯠set -x
ã§ç¢ºèªããŠã¿ããšããã§ãããã£ãšã¿ãŒããã«ã«ã¯ä»¥äžã®ããã«åºåããããšæããŸããããã°äžã§ã¯ã¹ããŒã¹ã«èŠãããããããŸããã s/
ã®åŸãã«ã¯ã¿ãæåãå
¥ã£ãŠããŸãã
+ sed 's/ //'
$'\t'
ã䜿ã£ãŠã¿ãæåãåãé€ãéã®äŸãããã€ãæžããŠãããŸãã
# è¡é ã®ã¿ãã ããåé€ sed s/^$'\t'// # å é ã®ã¿ãæåã ããåé€ sed s/$'\t'// # å šãŠã®ã¿ãæåãåé€ sed s/$'\t'//g
ãã $'\t'
ã䜿ããªãå Žå㯠printf ãªã©ã«åºåããŠããããŸããããäžæ®µã®äŸã§ã¯ããã«ã¯ãªãŒããå¿
èŠã«ãªããããããŸããã
# ã³ãã³ã眮æã§ã¿ãæåãåºå (1) sed s/"`printf '\t'`"// # ã³ãã³ã眮æ㧠sed ã¹ã¯ãªããããšåºå (2) sed "`printf 's/\t//'`" # å€æ°ã«ããå±é tab=`printf '\t'` sed s/${tab}//
æ¹è¡æåã«çœ®æãã
ã¿ãæåã®è©±ããéžããŸãããããæååãæ¹è¡ã«å€æããããå Žåã®è©±ã§ãããŸããšã©ãŒäŸã§ãã
sed s/\<br\>/$'\n'/
ãªããšã©ãŒã«ãªãã㯠sed ã«æž¡ãããã¹ã¯ãªãããèŠãŠã¿ãã°ããããŸããsed ã¯æ¹è¡ãã³ãã³ãã®åºåãã«ããŠããããäžèšã®æžãæ¹ã ãš2ã€ã®ã³ãã³ãã«åé¢ããŠããŸã£ãŠããããã§ãã
s/<br>/ /
æ£ããæ¹è¡ã«å€æããã«ã¯ä»¥äžã®ããã«æžããŸãããšã¹ã±ãŒãã®ä»æ¹ãã¯ãªãŒãã®ä»æ¹ã¯äººããããã§ãã®ã§ãããŸã§äžäŸã§ãã
sed s/\<br\>/$'\\\n'/
sed ã«æž¡ãããã¹ã¯ãªããã¯ãããªããŸããããã¯ã¹ã©ãã·ã¥ã§ã€ãªãã£ãŠããã®ã§1ã€ã®ã³ãã³ããšããŠæ±ã£ãŠãããŸãã
s/<br>/\ /
éã«ãæ¹è¡ã眮æããããå ŽåãããããšæããŸãããããã sed ã§ããããšãããšããªãé¢åãªã®ã§ä»ã®ã³ãã³ãã®äœ¿çšãããããããŸããïŒQiita ã«æžãããããªæ°ããããã©ïŒ
ãã®ä»
å€æ°ã䜿ã
ã¿ãã®è©±ã«æ»ããŸããå€æ°ã¯ã·ã§ã«ã«ãã£ãŠå
ã«å±éãããã®ã§ $'\t'
ã䜿çšããå Žåãšåãã§ãã
tab=$'\t' sed "s/${tab}//"
ã¯ã©ã¹ã䜿ã
[:cntrl:]
ãã[:blank:]
ã[:space:]
ãªã©ã䜿ãããšã§å¶åŸ¡æåã空çœãåãé€ãããšãã§ããŸãããã¿ãæåã ãããšããã®ã«ã¯åããŠããŸããã s/[ ]//
âïŒã¹ããŒã¹ãšã¿ãïŒãšæžãããã¯ããããããããªãšæããŸãã
sed "s/[[:cntrl:]]//"
IFS ããéšåæååå±éã§ã¿ãã ãåãåºã
bash ã§ã¯ã·ã§ã«ã® IFS ç°å¢å€æ°ã«ã¯ <ã¹ããŒã¹><ã¿ã><æ¹è¡> ãæ ŒçŽãããŠããã®ã§éšåæååå±éã§ã¿ãã ãã䜿çšããããšãã§ããŸããã·ã§ã«ã«ãã£ãŠã¯ãã®å±éã¯äœ¿ããŸããããIFS ãäžå®ã§ã¯ãªãã®ã§å±éºã§ããããã¯ãã ã®ãã¿ã§ãã®ã§å¿ããŠãã ããã
sed "s/${IFS:1:1}//"
tr ã䜿ã
çšéã«ãã£ãŠã¯ sed ããããã£ãšã·ã³ãã«ã§ãã
tr -d '\t'
sed ã¯ã·ã§ã«ã¹ã¯ãªãããã¿ãŒããã«äžã§äœ¿ãããšãããšã¯ãªãŒããããã¯ã¹ã©ãã·ã¥ãªã©ã®ããã§é£ãããªããŸãããŸã㯠sed ã¹ã¯ãªãããå¥ã§äœæããŠç·Žç¿ããŠã¿ãã®ããããšæããŸããã¿ãŒããã«ãã㯠-f
ãªãã·ã§ã³ã§ã³ãã³ããã¡ã€ã«ãæå®ã§ããŸãããã¢ããã¥ã¡ã³ã㧠fd ããèªãããšãã§ãããããŸãã
sed -f command.sed
- 2014幎06æ20æ¥ã«èšäºä¿®æ£