root@ROUTER:~# cat maccheck.txt logread | egrep ': STA |DHCPACK' | awk '{print $1 $2 $3 $9}' | sed -e 's/\( [0-9] \)/0\1/' | sed s/.\{15\}/&:/; s/: /:/g | cut -d : -f 1,2,4,5,6,7,8,9 | sed s/.\{13\}/&X/; | sed 's/:X/ /g' | sed 's/XX:XX:XX:XX:XX:XX/AAAA/g' | sort -u -rit OK when it's here: root@ROUTER:~# logread | egrep ': STA |DHCPACK' | awk '{print $1 $2 $3 $9}' | head -1Sep 2 03:03:25 XX:XX:XX:XX:XX:XXbut it's bad if I use the script that has further things in it: root@ROUTER:~# sh maccheck.txt |head -1Sep0 4 13:13 AAAAso the Sep0 is bad.. how to modify it to be Sep? root@ROUTER:~# logread | egrep ': STA |DHCPACK' | awk '{print $1 $2 $3 $9}' | sed -e 's/\( [0-9] \)/0\1/' | head -1Sep0 2 03:03:25 AAAASo the problem is with: sed -e 's/\( [0-9] \)/0\1/'Q: I need the same output, but without the 0 in Sep, how to do it?
Problem with sed
sed
\1 will give you everything listed in your group (the \( \) section).  Your group includes the spaces, so the zero will be put in, then the  2  will be added.  To fix, change to sed -e 's/ \([0-9]\) / 0\1 /'Examplebefore$ cat sample.txt | sed -e 's/\( [0-9] \)/0\1/' Sep0 2 03:03:25 XX:XX:XX:XX:XX:XXafter$ cat sample.txt | sed -e 's/ \([0-9]\) / 0\1 /'Sep 02 03:03:25 XX:XX:XX:XX:XX:XX