Thursday, November 14, 2019

How do I add text to the beginning and end of text file in Bash- Centos ?

First of All if you have Munltipe Files and you need to combine them all use

[root@centos /] # cat file 1 file2 file3 >combinedfile

Alos if you installed moreutils as described in below you can yuse

[root@centos /] # combine file1 and file2 and file3 >combinedfile

If you need to Add txt to begining of file

Let us say the combinedfile you may use one of the below two options

Method 1

1-[root@centos /] # echo 'first line text you want to add' | cat - combinedfie > temp && mv -f temp combinedfile

Method 2

a- Install moreutils
[root@centos /] # sudo yum install moreutils

b- Use sponge tool as following

[root@centos /] # echo 'first line text you want to add' | cat - combinedfie | songe  combinedfile



If  you need to Add txt to end of File 

[root@centos /] #cat <<EOT>> file1
test
test1 
EOT

[root@centos /] #

No comments:

Post a Comment