You're looking at too small a part of the command. A sedsubstitute command is usually seen in the form:
There are two sedsubstitute commands in this case separated by the semicolon (;).
In the first sedsubstitute command, the Basic Regular Expression is [^,]*: which matches a string of adjacent characters that are not a comma ([^,]) appearing zero or more times (*) followed by a colon (:) followed by a single space character. The Replacement String in this case is the empty string (which effectively removes the matched string). And the flags in this case is g which requests that the substitution be applied globally to all non-overlapping strings that match the BRE.
In the second sedsubstitute command, the BRE is , which matches a comma character, the replacement string is a space character, and, again, the g flag requests that each comma found on the line be replaced by a space.
I wonder if one can include an optional comma ,\{0,1\} in the main substitution
One can do that, but if you do the output from the input line:
becomes:
instead of:
One could also get rid of the space after the colon in the BRE:
and that would make the output from the above input line be:
which is almost what is wanted, but has an extraneous leading space on every output line.
One could also try:
and that looks like the desired output to the naked eye, but has an extraneous trailing space on every output line.
The following seems to do what is wanted with a single sed substitution command:
but it is not something that I would suggest for someone who is just learning how to use sed and learning how to write sed BREs (unless I was trying to show an example of the sed-specific extensions to standard BREs and the use of back references in replacement strings).
Note that all of the examples above work with standards-conforming versions of sed, but might need an added option on the command line to make it work with GNU sed. For example, the last example above, when using GNU sed, probably needs to be invoked with:
This User Gave Thanks to Don Cragun For This Post:
I have entries like below in a file
11.22.33.44:80
22.33.44.55:81
:::587
:::465
What I need is to take out the part after colon ( : )
Output should be as follows.
80
81
587
465
I used cut -d: -f 2 but its not working as dedired. (2 Replies)
Ok I would like to do the following
file test contains the following lines. between the lines ABC there may be any amount of lines up to the next ABC entry.
I want to grep for the filename.txt entry and print the lines in between (and including that line) up to and including the last line... (3 Replies)
There was a sample code on forum I found sometime back:
$ f() { local foo=; : ${foo=unset}; declare -p foo; }; f
declare -- foo=""
$ f() { local foo; : ${foo=unset}; declare -p foo; }; f
declare -- foo="unset"
Can someone explain why was colon (:) is being used here. Whats its use? (4 Replies)
Hi I have a requirment here. I have to out the string after the particular word. for example i have the to extract the first word after the word disk. help me out. i have tried the folloing code but it is not giving the output which i need.
awk -F"*disk " '{print $1}'
grep -n -o '' file
Input... (2 Replies)
Hi,
Is there a way in Korn Shell that I can run multiple commands stored as a semi-colon separated string, e.g.,
# vs="echo a; echo b;"
# $vs
a; echo b;
I want to be able to store commands in a variable, then run all of it once and pipe the whole output to another program without using... (2 Replies)
i have a file that looks like this
ABC123
aaaaaaaaaaaaaaasssssssssssssssffhhh
ABC234
EMPTY
ABC652
jhfffffffffffffffffffffffffffffffffffkkkkkkkkkkkk
i want to grep "EMPTY" and print ABC234 (3 Replies)
Dear All,
I am new to shell script.I want to print following string:
"E:\OutputRef\ExtendedTestObjectModel\Test.txt"
For that i am using:
echo "$ADL_ODT_REF${ADL_ODT_SLASH}ExtendedTestObjectModel${ADL_ODT_SLASH}$ResultFile"
where - $ADL_ODT_REF is E:\OutputRef
$ADL_ODT_SLASH... (5 Replies)
How to print the strings within a line between two spaces .
<ns1:providerErrorCode>141</ns1:providerErrorCode> <ns1:providerErrorText>business_rule_exception-Server.404:Cannot proceed because the subscriber with phone number is either suspended or the account has an unpaid... (8 Replies)
I know how to grep, copy and paste a string from a line. Now, what i want to do is to find a string and print a string from the line below it. To demonstrate:
Name 1: ABC Age: 3
Sex: Male
Name 2: DEF Age: 4
Sex: Male
Output:
3 Male
I know how to get "3". My biggest problem is to... (4 Replies)
Hi, all,
I wonder if I can use sed to insert a string which has a colon.
I have a txt file a.txt like the following
TRAIN/DR1/FCJF0/SI1027.MFC
TRAIN/DR1/FCJF0/SI1657.MFC
I want to insert a string C:/TIMIT/TIMIT at the begining of each line.
I use the commond:
TIM=C\:/TIMIT/TIMIT... (2 Replies)