I'd be most obliged to anyone who might be able to tell me how I can extract all characters up to the first space or tab character after having tested that what follows the space/tab is another specified substring? For example a file containing
php server-side
asp server-side
css client-side
html client-side
golang server-side
when read line-by-line could be used to generate the string
php asp golang
i.e. with the lines ending client-side dropped out altogether and the lines containing server-side truncated at the space.
This command will do the trick,
grep "server-side" filename|cut -d ' ' -f1|tr '\n' ' '
Explanation as follows;
grep "server-side" filename
It will capture only lines matched with the string server-side.
cut -d ' ' -f1
cut
commmand will cut first column of the table by delimiter space.
tr '\n' ' '
tr
command will make all new line character replaced with a space.
Output will be exactly what OP mentioned in question(requirement):
php asp golang
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With