sed help adding parenthesis


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed help adding parenthesis
# 1  
Old 07-19-2013
sed help adding parenthesis

I have the following data and want to put parenthis around the numbers:

Code:
 
PARTITION PERIOD_MIN   VALUES LESS THAN 10649 TABLESPACE ODS_DAILY_MF_AUM,
 PARTITION PERIOD_10649 VALUES LESS THAN 10650 TABLESPACE ODS_DAILY_MF_AUM,
 PARTITION PERIOD_10650 VALUES LESS THAN 10651 TABLESPACE ODS_DAILY_MF_AUM,
...
...
...

The output should look like this

Code:
 
PARTITION PERIOD_MIN   VALUES LESS THAN (10649) TABLESPACE ODS_DAILY_MF_AUM,
 PARTITION PERIOD_10649 VALUES LESS THAN (10650) TABLESPACE ODS_DAILY_MF_AUM,
 PARTITION PERIOD_10650 VALUES LESS THAN 1(0651)TABLESPACE ODS_DAILY_MF_AUM,
...
...
...

Can somebody provide me with a SED or AWK statement that can do this in one shot.

Thanks to all who answer
# 2  
Old 07-19-2013
Code:
awk '{$(NF-2)="("$(NF-2)")"}1' file

This User Gave Thanks to Yoda For This Post:
# 3  
Old 07-19-2013
Try also
Code:
sed -r 's/ ([0-9]+) / (\1) /' file
PARTITION PERIOD_MIN   VALUES LESS THAN (10649) TABLESPACE ODS_DAILY_MF_AUM,
 PARTITION PERIOD_10649 VALUES LESS THAN (10650) TABLESPACE ODS_DAILY_MF_AUM,
 PARTITION PERIOD_10650 VALUES LESS THAN (10651) TABLESPACE ODS_DAILY_MF_AUM,

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

adding a number with sed or awk.

Hi.. I have this delicate problem..:wall: I have this huge ldif file with entry's like this example below.. And I need to change the following entrys. telephoneNumber: emNotifNumber: billingnumber= BillingNumber: Al these entrys has a number like 012345678 and it needs to add one more... (15 Replies)
Discussion started by: pelama
15 Replies

2. Shell Programming and Scripting

Need help with Sed (replacing parenthesis and comma)

I have the following text as an input text: input.txt Results('Toilet', 'Sink', ) and i want to remove the last comma so the output is output.txt Results('Toilet', 'Sink' ) I tried using the following sed command, but I get a parsing error: sed s/, \)/\)/g input.txt >... (5 Replies)
Discussion started by: jl487
5 Replies

3. Shell Programming and Scripting

adding text with sed

sed 's/<\/body>/<A HREF='"$index"'>'"$description"'<\/A>\ <\/body>/' "$index" This will work from the command prompt, but not from my ksh script. Why not? sed: command garbled: s/<\/body>/<A HREF=/accounts/students/b/bmwg6c/public_html/index.html>I would like to call it white... (4 Replies)
Discussion started by: robin_simple
4 Replies

4. Shell Programming and Scripting

sed adding a blank line

I use the following as part of a script to correct for a faulty hostname file. # get the domain name read -r thehostname < /etc/hostname dom="$(echo $thehostname | cut -d'.' -f2)" numchar=${#dom} if then echo "It appears as though the hostname is not correctly set." echo "Hostname has... (5 Replies)
Discussion started by: bugeye
5 Replies

5. UNIX for Dummies Questions & Answers

Adding space after character using sed?

dears i have the data below, i want a command ( i think it should be sed) that add a space after the seconds as below : Jun 24 22:28:18966568406148@ Jun 24 05:47:35966555747744@ Jun 24 05:47:53966560825239@ Jun 24 06:07:52966541147164@ Jun 24 15:49:55966566478883@ thanks... (5 Replies)
Discussion started by: thehero
5 Replies

6. Shell Programming and Scripting

Multiline parenthesis matching, with e.g. SED script, in LaTeX doc

In a LaTeX manuscript, I need to replace many occurrences of \emph{some string} with some string, i.e. whatever string is inside. The string inside often may extend over several lines, and there may be other occurences of curly brackets inside it. So for example \emph{this \it{is} a... (5 Replies)
Discussion started by: sune
5 Replies

7. Shell Programming and Scripting

adding another field to SED output

Dear experts, I have a file called "check" with contents like below i used the sed command like below to get the value of "success" and "failed" only My question is how can i get the value to include the time "03:15", so that i can get a value such as below : - Appreciate... (4 Replies)
Discussion started by: aismann
4 Replies

8. Shell Programming and Scripting

sed for adding word

hello i have a file (myfile) contains line as follows /home/mytarget/myproject i want to add a pattern at the end of this line. my pattern is- /.*mk i want like it - /home/mytarget/myproject/*.mk i tried sed like sed 's/$//*.mk/' myfile > newfilename, but not wrking. pls... (2 Replies)
Discussion started by: shailesh_arya
2 Replies

9. UNIX for Dummies Questions & Answers

sed - adding new line

I want to use sed to look for spaces in text and when find one move the next word to the next line. I used: sed 's/ /\n/g' out > new However when there is more than one space between two words it adds more lines between them. And I just want the words to be one under another. How can I... (2 Replies)
Discussion started by: sovixi
2 Replies

10. UNIX for Dummies Questions & Answers

another sed question about parenthesis

hi, I'm trying to use sed to erase everything, up to, and including, the first closing parenthesis. for example: input: blah blah blah (aldj) test (dafs) test test. output: test (dafs) test test. how would i do this? I was fooling around with the parenthesis, and i only got it to apply to... (5 Replies)
Discussion started by: gammaman
5 Replies
Login or Register to Ask a Question