how to find and add a string to a file in linux
- by user2951644
How can I check a file for a string if missing the string automatically add it for example
Input
Input file test.txt
this is a test text for testing purpose
this is a test for testing purpose
this is a test for testing purpose
this is a test text for testing purpose
I would like to add "text" to all the lines
Desired Output
this is a test text for testing purpose
this is a test text for testing purpose
this is a test text for testing purpose
this is a test text for testing purpose
Is it possible? many thanks in advance
Hi guys thanks for all the help, for my case is not that simple. I wont know which line will be different and in the middle string it will not only have a single string. i will give a clearer case
Input file test.txt
Group: IT_DEPT,VIP Role: Viewer Dept: IT
Group: IT_DEPT,VIP Dept: IT
Group: FINANCE LOAN VIEWER Role: Viewer Dept: FINANCE
Group: FINANCE LOAN VIEWER Dept: FINANCE
Desired output file test2.txt
Group: IT_DEPT,VIP Role: Viewer Dept: IT
Group: IT_DEPT,VIP Role: - Dept: IT
Group: FINANCE LOAN VIEWER Role: Viewer Dept: FINANCE
Group: FINANCE LOAN VIEWER Role: - Dept: FINANCE
So those that are missing "Role:" will be added "Role: - ", hope this clear things out, thanks in advance again