linux - insert symbol between numbers -


i have file in linux os containing random numbers:

1 22 333 4444 55555 666666 7777777 88888888 

now, have 2 conditions: 1. remove last 3 digit every entry , put / in between rest. 2. numbers <=3, add/replace / symbol.

command trying fulfilling 1st requirement is:

 sed -e 's|\(.\)|\1/|g;s|\(.*\)/\(.\/\)\{3\}|\1|g' 

desired out required:

/ / / 4 5/5 6/6/6 7/7/7/7 8/8/8/8/8 

please help.

something might work you:

% sed 's/.\{1,3\}$//;s/./\/&/g;s/.//;s/^$/\//' file / / / 4 5/5 6/6/6 7/7/7/7 8/8/8/8/8 

no smart moves here:

s/.\{1,3\}$//; # remove last 3 character s/./\/&/g;     # insert / before each character s/.//;         # remove first character (it's /) s/^$/\//       # insert slash on empty lines 

alternative solution gawk:

awk -v fs='' -v ofs='/' '{if (nf > 3) nf=(nf-3); else $0 = ofs}1' file 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -