Re: Problem in making a script

amritpal pathak wrote:
still i am little bit confuse to understand it "how it is
happening".Please sir,tell me what each line is doing .It will make
me fully understand it


Make a temporary file which doesn't conflict with existing files.

head -n $((4 - 1)) "abc.tex" > "$TEMP"

Copy the first lines from the original file to the temporary file.

echo "$fname" >> "$TEMP"

Append the user input to the temporary file.

LEN=$(cat "abc.tex"|wc -l)
tail -n $(($LEN - 4)) "abc.tex" >> "$TEMP"

Append the remaining lines from the original file to the temporary file.

mv "$TEMP" "abc.tex"

Replace the original file by the temporary file.

If you want to learn more about the individual commands, please read the
man pages:

man mktemp head echo cat wc tail mv


ubuntu-users mailing list
Modify settings or unsubscribe at:

Relevant Pages

  • RE: Locked for editing???
    ... removable disk, such as a floppy diskette, the disk has been removed. ... file name and places this file in the same folder as the original file. ... The process was interrupted while creating the temporary file because you ... If the interruption was caused ...
  • Re: Newbie howto question.
    ... I can identify the tagged information, ... >said info and write it to the html file, ... create a new temporary file for writing ... read the first line from original file. ...
  • Re: Serialized r/w access to a collection from multiple processes - DLL or EXE?
    ... one or more instances of our app EXEs will be accessing the same ... Flush memory content into new temporary file. ... If write succeeds, then rename original file. ...
  • RE: How is the ~$... file created when you open a document used?
    ... This temporary file holds the logon name of the person ... If the Owner File is damaged or missing the error message changes to: ... Word automatically deletes the Owner File when the original file is closed. ... I understand that Word opens a "copy" of the file and you ...
  • Re: c++ fstream writing to existing file
    ... rewind the original file. ... copy the contents from the temporary file back to the original. ... The universe is a figment of its own imagination. ...