how to find and add a string to a file in linux
Posted
by
user2951644
on Stack Overflow
See other posts from Stack Overflow
or by user2951644
Published on 2013-11-10T22:37:47Z
Indexed on
2013/11/11
21:54 UTC
Read the original article
Hit count: 131
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
© Stack Overflow or respective owner