Simple Scripting Problem

Hi there,

I was trying to add a line of text in the middle line of a file.

I have counted the lines in the file, and then I divide it into 2, after that I am stuck on how am I suppose to append the line on that file? When I tried to use this command 'second line >> filename' it appends it at the end of the file and not put them in the middle. I know I have to use the for loop to do it, but can anyone tell me what other commands that I need to use? I don't want to use sed or awk because I want to understand it through the long way.

If you do not want to use sed or awk, then you can use it with simple comamands. But you should be knowing the line number

For example file contains

cat yourfile
line 1
line 2
line 3
line 4

I think your intension is to add a line after line 2.

head -2 your file > newfile
echo "new line" >> newfile
tail -2 your file >>newfile

thanks for that. I am stuck with this too:
I have done this command env >> filename for 3 times.
I am writing a script to append the PWD, USER, MAIL, LOGNAME, HOME into something like this:
1) PWD=/home/..
2) USER=user.user
3) MAIL=/var/spool/mail/user.user
4) LOGNAME=user.user
5) HOME=/home/user.user
I have used grep $PWD filename and it gives the output that I want:
PWD=/home/..
PWD=/home/..
PWD=/home/..

Is there anyway that I could display PWD, USER, MAIL, LOGNAME and HOME all at the same line? IS there anyway I could add the number and the brackets for each output? Again, I don't want to use SED or AWK because I want to use the condition statements to try and do it.

You need not redirect to any file to display the content in single line. Just give

echo "PWD=$PWD USER=$USER MAIL=$MAIL LOGNAME=$LOGNAME HOME=$HOME"