I have a little problem with a small script. The textfile has a lot of entries like:
permission-project1-admin
permission-project2-admin
....
The script looks like this (indeed, it is an awful one but still helps me):
#!/bin/bash
for i in $(cat adminpermission.txt); do
permission=$(echo $i | cut -f1)
printf "dn:$permission,ou=groups,dc=domain,dc=com \n"
printf "objectclass: groupOfUniqueNames \n"
printf "objectclass: top \n"
printf "description: \n"
printf "cn:$permission \n\n"
done
The output looks fine, but because the textfile has a newline character at the end, the first line of printf is devided into two lines like:
dn:permission-project1-admin
,ou=groups,dc=domain,dc=com
objectclass: groupOfUniqueNames
objectclass: top
description:
cn:permission-project1-admin
My question is, how I can eliminate the newline character between the first two lines?
Do it correctly in the first place.
while read permission rest
do
...
done < adminpermission.txt
Also, heredocs.
Try:
$(echo $i | tr -d "\n" | cut -f1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With