How to get rid of double quote in sed.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get rid of double quote in sed.
# 1  
Old 07-28-2008
Power How to get rid of double quote in sed.

Hi,

i am using sed command to grep just a valuable data for my report generating. Thanks to the person who assists me on before thread. the problem that i encounter now is when i executed below command
The output will give me like below output in between the data, there is a double quote. How do i get rid of it.

I know it can be formated during when i print it out but how to do that.


example = ids-job-identifier = "dlm_01:1:180748"

Command sed execute:
Quote:
sed 's/.*\('"$dsmid"' = \"[^"]*\"\).*\('"$jqmid"' = \"[^"]*\"\)..*/\1/g' $logDir/$reportlogname.aim.log
Sample Output that i get:
Quote:
ids-job-identifier = "dlm_01:1:180748" dpa-job-identifier = "jqm_APJFIREWALL02:1270283169"

thanks
# 2  
Old 07-28-2008
Code:
sed -e 's/.*\('"$dsmid"' = \"[^"]*\"\).*\('"$jqmid"' = \"[^"]*\"\)..*/\1/g' \
  -e 's/"//g' $logDir/$reportlogname.aim.log

You could also avoid grabbing the double quotes in the first place, but that is slightly more complex, and doesn't easily let you remove any double quotes outside of the search expression. (I gather you want to remove the double quotes around the dpa-job-identifier value, too.)
# 3  
Old 07-28-2008
you don't have to grapple with that mess sed gives you if you use double quotes as field delimiters. I do not understand your requirement enough but i can tell you, there's better ways to what you want without that much regexp.
# 4  
Old 07-28-2008
Hi All,

Thanks for the advice. My attention actually to grep a data from file A like below and put the ouput into file B. Currently what i am doing is i used the command below:

Data to grep.
Quote:
ids-job-identifier = "dlm_10:1:178321" dpa-job-identifier = "jqm_APJFIREWALL:779749767" logical-destination = "cbax91pc17" physical-destination = "p_cbax91pc17" job-state = "retained" job-completion-status = "success" processing-time = "1"
ids-job-identifier = "dlm_01:1:180748" dpa-job-identifier = "jqm_APJFIREWALL02:1270283169" logical-destination = "jpnx198" physical-destination = "p_jpnx198" job-state = "retained" job-completion-status = "success" processing-time = "8"
Command used:
Quote:
sed 's/.*\('"$dsmid"' = \"[^"]*\"\).*\('"$jqmid"' = \"[^"]*\"\).*\('"$ldest"' = \"[^"]*\"\).*\('"$pdest"' = \"[^"]*\"\).*\('"$jstate"' = \"[^"]*\"\).*\('"$jstatus"' = \"[^"]*\"\).*\('"$proctime"' = \"[^"]*\"\).*/\1 \2 \3 \4 \5 \6 \7/g' $logDir/$reportlogname.aim.log > $logDir/trim.$reportlogname.aim.log

The problem with this output i get double quote "". So i want to get rid of the double quote "".

Output Currently I get:
Quote:
dpa-job-identifier="jqm_APJ03:1108609378" logical-destination="hpkkdp01" job-completion-status="aborted-in-printing" processing-time="3"
dpa-job-identifier="jqm_APJ03:1108674914" logical-destination="hpkkdp01" job-completion-status="aborted-in-printing" processing-time="4"
# 5  
Old 07-28-2008
Code:
sed -e 's/.*\('"$dsmid"' = \"[^"]*\"\).*\('"$jqmid"' = \"[^"]*\"\).*\('"$ldest"' = \"[^"]*\"\).*\('"$pdest"' = \"[^"]*\"\).*\('"$jstate"' = \"[^"]*\"\).*\('"$jstatus"' = \"[^"]*\"\).*\('"$proctime"' = \"[^"]*\"\).*/\1 \2 \3 \4 \5 \6 \7/g' -e 's/"//g' $logDir/$reportlogname.aim.log > $logDir/trim.$reportlogname.aim.log


Last edited by era; 07-28-2008 at 06:26 AM..
# 6  
Old 07-28-2008
without too much regexp, here's an easier to read approach
Code:
awk 'BEGIN{ RS="\" ";}
/dpa-job-identifier|logical-destination|job-completion-status|processing-time/{
 gsub(/"/,"")
 print $0 
}' file

output:
Code:
# ./testnew.sh
dpa-job-identifier = jqm_APJFIREWALL:779749767
logical-destination = cbax91pc17
job-completion-status = success
processing-time = 1
ids-job-identifier = dlm_01:1:180748
dpa-job-identifier = jqm_APJFIREWALL02:1270283169
logical-destination = jpnx198
job-completion-status = success
processing-time = 8

i leave it to you to arrange the output
# 7  
Old 07-28-2008
Hi ghostdog74 and era,

Thanks for your assistance. It work now for me.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing all but the first and last double quote in a line with a single quote with awk

From: 1,2,3,4,5,This is a test 6,7,8,9,0,"This, is a test" 1,9,2,8,3,"This is a ""test""" 4,7,3,1,8,"""" To: 1,2,3,4,5,This is a test 6,7,8,9,0,"This; is a test" 1,9,2,8,3,"This is a ''test''" 4,7,3,1,8,"''"Is there an easy syntax I'm overlooking? There will always be an odd number... (5 Replies)
Discussion started by: Michael Stora
5 Replies

2. Shell Programming and Scripting

Replacing Double Quote in Double Quote incsv file

Hi All , We have source data file as csv file and since data could contain commas ,each attribute is quoted into double quotes.However problem is that some of the attributa data also contain double quotes which is converted to double double quote while creating csv file XLs data : ... (2 Replies)
Discussion started by: Shalini Badal
2 Replies

3. Shell Programming and Scripting

Replace double quotes with a single quote within a double quoted string

Hi Froum. I have tried in vain to find a solution for this problem - I'm trying to replace any double quotes within a quoted string with a single quote, leaving everything else as is. I have the following data: Before: ... (32 Replies)
Discussion started by: pchang
32 Replies

4. Shell Programming and Scripting

Double quote filenames

Hi, I need to double quotes filenames in the following string: /tmp/*file1 /tmp/*file2 /tmp/*file3 /tmp/*file4I tried to do this using sed, but it double quotes every character :wall: $ echo... (10 Replies)
Discussion started by: Subbeh
10 Replies

5. Shell Programming and Scripting

getting value between double quote

Can somebody supply me with a simple way to get a value between two double quotes? Example: input = ADR base is "/u01/app/oracle" output = /u01/app/oracle Thanks to all who answer (4 Replies)
Discussion started by: BeefStu
4 Replies

6. Shell Programming and Scripting

double quote as the delimiter

I'm trying to extract a column from a csv file with either cut or awk but some of the fields contain comma with them: "Field1","Field2, additional info","Field3",...,"Field17",... If I want to extract column 3 and use comma as the delimiter, I'll actually get the additional info bit but not... (4 Replies)
Discussion started by: ivpz
4 Replies

7. Shell Programming and Scripting

Regex in grep to match all lines ending with a double quote (") OR a single quote (')

Hi, I've been trying to write a regex to use in egrep (in a shell script) that'll fetch the names of all the files that match a particular pattern. I expect to match the following line in a file: Name = "abc" The regex I'm using to match the same is: egrep -l '(^) *= *" ** *"$' /PATH_TO_SEARCH... (6 Replies)
Discussion started by: NanJ
6 Replies

8. Shell Programming and Scripting

double-quote inside double-quote

hey all, i made a simple .sh like this: echo "<style media="screen" type="text/css">@import url("main.css");</style>" but the output is: <style media=screen type=text/css>@import url(main.css);</style> i want to keep double-quotes, can anyone help me? thanks (3 Replies)
Discussion started by: indraf
3 Replies

9. Shell Programming and Scripting

single or double quote in SED

i m trying the following command but its not working: sed 's/find/\'replace\'/g' myFile but the sed enters into new line # sed 's/find/re\'place/g' myFile > I havn't any idea how to put single quote in my replace string. Your early help woud be appreciated. Thanx (2 Replies)
Discussion started by: asami
2 Replies
Login or Register to Ask a Question