I would like to extract a user name from the file between the keywords / and NET like below. How can I do so with programs like awk, sed or cut.from:audit: command=true   rsa1/abc.domain.net@xyz.DOMAIN.NET runningaudit: command=true   user2/xyz.domain.net@xyz.DOMAIN.NET executingto:audit: command=true   rsa1 runningaudit: command=true   user2 executing
shell script to extract between characters
shell script;text processing;sed;awk
Using sed:< inputfile sed 's/\/.*NET//' > outputfileUsing sed in-place:sed -i.bak 's/\/.*NET//' inputfileCommand #1 breakdown:< inputfile: redirects the content of inputfile to sed's stdin> outputfile: redirects the content of sed's stdout to outputfileCommand #2 breakdown:-i.bak: Forces sed to create an inputfile.bak backup file and to edit inputfile in-placeinputfile: Forces sed to read the input from inputfileRegex breakdown:s: asserts to perform a substitution/: starts the search pattern\/: matches a / character.*NET: matches any number of any character up to the end of a NET string/: stops the search pattern / starts the replace pattern/: stops the replace patternSample output:~/tmp$ cat inputfileaudit: command=true   rsa1/abc.domain.net@xyz.DOMAIN.NET runningaudit: command=true   user2/xyz.domain.net@xyz.DOMAIN.NET executing~/tmp$ < inputfile sed 's/\/.*NET//' > outputfile~/tmp$ cat outputfile audit: command=true   rsa1 runningaudit: command=true   user2 executing~/tmp$ sed -i.bak 's/\/.*NET//' inputfile~/tmp$ cat inputfile.bakaudit: command=true   rsa1/abc.domain.net@xyz.DOMAIN.NET runningaudit: command=true   user2/xyz.domain.net@xyz.DOMAIN.NET executing~/tmp$ cat inputfileaudit: command=true   rsa1 runningaudit: command=true   user2 executing~/tmp$ 