Complex Sed/Awk Question?

Hello,

So i have this file called /apps/turnout which looks like that of the contents of the /etc/shadow (but not exactly)

the file has a long list in it. basically, the contents of this file looks something similar to the following:

jajajajalala:D#$#AFVAdfda
lalabavisof:#%R@fafla#$
anthovolad:#%)@#Fafdf834

The first field is the username, the second field is something else.

now, how can i insert a new username into the this file in a alphabetical order without actually going into the file. i hate having to vi/emacs/ed or whatever when i dont have to.

so, in otherwords, say i have a name like:

mjackson:#$#$#$%adf#$#

and i want to insert it into the file /apps/turnout so it is placed inside the file in its alphabetical place, how do i accomplish that from the command line.

(i dont want to do the other technique of copying the original file, editing the copy and then rewriting the original.)

try something like that :

echo 'mjackson:#$#$#$%adf#$#' >> /apps/turnout 
sort -t: -k1,1 -o /apps/turnout  /apps/turnout 

Jean-Pierre.

here is the tool kind of stuff

#! /usr/bin/bash
echo -e "Enter the username :\c"
read r
cat /apps/turnout|cut -d ":" -f1|grep $r
if [ $? -eq 0 ]; then
echo "username already found"
else
echo $r':#$#$#$%adf#$#' >> /apps/turnout
sort -t ":" -k1,1 -o /apps/turnout /apps/turnout
fi

Thanks guys. I'll try your suggestions. Thanks a million :slight_smile: