Insert text lines before the first line of a file

When editing text files, sometime we need insert lines before the first line in files using the Linux shell. Text lines from one file to another file are often appended at the end. If text lines are to be inserted at the beginning of a file, this article shows this as follows.

How to insert text lines to the first line in file

The command sed can be used to format and insert text, sed – stream editor provide the options for this, with in-place (-i) and (i) for insert text.

$ sed -i '1 i\insert this before' file.txt

Insert text line before, the following command does the same thing.

$ sed -i '1i insert this before' file.txt

Multiple text lines can also be inserted at the top.

$ sed -i '1i first line\nsecond line\nthird line' file.txt

If you want the contents of a file to be at the top of another desired file. Being insert the text lines before at the top with perform this command.

$ printf '%s\n' '0r file.1st' x | ex file.2nd

This will open file.2nd in ex (Vim in Ex mode), read in the full contents of the file.1st at the top, and then save the modified buffer back to file.2nd.

In this example, the file.1st has the following content.

first line
second line
third line

The second file has the following content.

fourth line
fifth line
sixth line

after merging the file.2nd has this content.

first line
second line
third line
fourth line
fifth line
sixth line

  Another simple approach is to rename the original filename to say file.tmp and using cat to append with >> to filename1 then rename filename1 back to filename.

Conclusion

This post describes how to. When editing text files, you can insert text lines before at the beginning of a file. Lines of text from one file to another are often appended at the end. However, if the content to be added at the top, this is explained in a few steps here. It’s always worth trying, and have fun trying it out.

There is no script engine for file extension vbs, Fix REG ADD VBS

Registering REG ADD VBS key Visual Basic Script become executable.

For reasons that are not known, Windows occasionally fails to run files of type .vbs (Visual Basic Script). Double-clicking does not execute the VB script file, instead the Windows Script Host error occurs.

There is no script engine for file extension vbs, Fix REG ADD VBS

Cause

This is a Windows issue. The proper association for .vbs file type is not set properly. There are different recommendations on how to fix this error message. The problem is caused by associating .vbs files with a program other than Microsoft Windows Based Script Host (the default).

Solution

The following registration using REG add the keys by opening a command prompt as an administrator.

Fix REG ADD Key to run VBS Script

REG ADD "HKCR\.vbs" /ve /t REG_SZ /d "VBSFile" /f
REG ADD "HKCR\.vbs" /v "PerceivedType" /t REG_SZ /d "text" /f
REG ADD "HKCR\.vbs" /v "Content Type" /t REG_SZ /d "text/plain" /f
REG ADD "HKCR\.vbs\PersistentHandler" /ve /t REG_SZ /d "{5e941d80-bf96-11cd-b579-08002b30bfeb}" /f

By inserting the REG lines, the shortcut for VB Script files (.vbs) is added to the registry.

Visual Basic – VBS Script files can now be run in a Windows 10 and Windows 11 command line environment.

Another alternative possibility by re-associating the .vbs script files with the following command:

assoc .vbs=VBSFile

In this particular situation, the customer had .vbs script files already associated with Microsoft Windows Based Script Host already.

If that is the same case for you, check the following reference under HKEY_CLASSES_ROOT.vbs and make sure the vbs script files is assigned to “VBSFile”.

VBScript (“Microsoft Visual Basic Scripting Edition”) is an Active Scripting language developed by Microsoft that is modeled on Visual Basic. It allows Microsoft Windows system administrators to generate powerful tools for managing computers without error handling and with subroutines and other advanced programming constructs. It can give the user complete control over many aspects of their computing environment.

Exit mobile version