Sorry, in my first sample the .* (capture any characters) was wrongly at the end, belongs to the beginning.
You can add a second substitution, the trick is the order.
With awk
This User Gave Thanks to MadeInGermany For This Post:
There are a few reasons why your original sed script can't work.
Your first asterisk in your RE needs a period before it.
There is nothing in your script to avoid printing lines that do not contain /lib.
There is nothing in your RE that will stop looking when the first occurrence of /lib is found (and if you're looking for /lib instead of something like => you're going to have more problems because /lib occurs twice in most of the fields you want to print.
Since your sed command contains unquoted shell pathname matching meta characters there is also a slight danger that the RE in your sed substitute command could be destroyed by actually matching the pathname of an existing file.
Note that in post #3 where you said you had the output you wanted, there was a line in the output:
that does not appear in your subsequent posts nor in the output produced by MadeInGermany's suggestions. Note that there is no => in the input lines:
which are the two input lines that end up producing the missing line of output.
If you still want that line of output try the command:
and see if it works for you. It works OK for me when using ksh or bash on macOS Mojave (version 10.14.6) with the sample data you provided. If the leading spaces shown in your sample data is really a tab character instead of being eight spaces, you will need to make a minor adjustment to the BRE. Note that invoking tr and uniq is not needed. The work that they do can all be done by sed and sort.
If you don't need the output sorted, but just want to get rid of duplicates, you can also try the following which just needs awk (with no sort required):
This User Gave Thanks to Don Cragun For This Post:
I have this command to replace the version value from PROGRAM (for example here PROGRAM == player) by NEWVERSION
sed "/^ *$PROGRAM:/{N; s/*$/ $NEWVERSION/;}" -i $PRDFILE
player:
version: V6R2013xD3HF5v1
player_old:
version: V6R2013xD3HF5v1
partchecker:
version:... (2 Replies)
Hi,
I have a text file containing 2 lines as follows:
I'm trying to extract all the strings following an "AME." The output would be as follows:
BUSINESS_UNIT
PROJECT_ID
ACTIVITY_ID
RES_USER1
RESOURCE_ID_FROM
ANALYSIS_TYPE
BI_DISTRIB_STATUS
BUSINESS_UNIT
PROJECT_ID
ACTIVITY_ID... (5 Replies)
Hello,
I have huge number files in a directory. All files have the data. I want extract data. I want all output write to single csv file.
following codes works. Thank you very much for help.
sed -n '/.*Content$txtE_Zip" type="text" value="\(*\)" maxlength.*/s//\1/p' *>file1
sed -n... (5 Replies)
I have an xml file that generally looks like this:
"<row><dnorpattern>02788920</dnorpattern><description/></row><row><dnorpattern>\+
44146322XXXX</dnorpattern><description/></row><row><dnorpattern>40XXX</dnorpattern><description/></row><row><dnorpattern>11</dn... (4 Replies)
Hello,
I am new to sed and am trying to extract a word using sed.
for example i have a line "const TotalAmount& getTotalAmount() const; " in the file test.txt
I am trying to extract getTotalAmount() from the line.
For this i tried
cat test.txt | sed -n 's/.*get*\(\)//p
But... (8 Replies)
I have the following string:
<min-pool-size>2</min-pool-size>
When I pipe the string into the following code I am expcting for it to return just the value "2", but its just reurning the whole string. Why??
sed -n '/<min-pool-size>/,/<\/min-pool-size>/p'
Outputting:... (13 Replies)
I am trying to extract "securitySettings" out of line:
<a ref ="http://localhost:5654/securitySettings">
using sed as follows:
name = `grep "localhost" file.html | sed -n 's/.**\/\(.*)/\">/\1/p'`
But it didn't run, seems have some syntax error. Do anybody knows why?
Thank you very... (11 Replies)