i am trying te write a shell script in alphametic ,
i have 5 parameters like this
$alphametic 5790813 BEAR RARE ERE RHYME
to get
ABEHMRY -> 5790813
i tried this :
#!/bin/bash
echo "$2 $3 $4 $5" | sed 's/ //g ' | sed 's/./&\n/g' | sort -n | sed '/^$/d' | uniq -i > testing
paste -sd '' testing > testing2
sed "s|^\(.*\)$|\1 -> ${1}|" testing2
but i get error (with the last command sed), i dont know where is the problem .
>Solution :
#!/bin/sh
val="$1"
shift
printf '%s' "$@" | awk -v FS='' -v OFS='\n' '{$1=$1}1' | sort -n | uniq | tr -d '\n'
printf " -> %s\n" "$val"
shiftremoves$1from the arguments.$@will then contain all the arguments but the first one, and the old$2will then be$1,$3will be$2, etc…printf '%s' "$@"concatenates all the arguments into a single stringawk -v FS='' -v OFS='\n' '{$1=$1}1'outputs each character verticallytr -d '\n'removes all\ncharacters