I have a file that contains a single line with usernames followed by their other information.
For instance the file contains:
Clara01{25 characters of info}Betty29{25 characters of info}Edith34{25 characters of info}Raji11{25 characters of info}
All in a single very long line with many usernames followed by 25 characters of their information.
Now, I want to search Betty29 and then delete/remove the substring Betty29{25 characters of info}. That is, how should I delete Betty29 and then next 25 characters. How should I do that in Linux shell scripting?
I have read about sed command but I still could not figure out. I am new to shell scripting so please be kind.
readarray -d'}'to access the file as an array.Betty29andunsetthat element.printf '%s'the whole"${array[@]}"as an output.Now let’s test it:
Output:
Presumably, this removes all occurrences of
Betty29. If you want to remove only the first one and make it “more efficient”, just add abreakinto thefor-loop once the match is found.