I was testing some and from this string try to remove all ", but not \"
Code:
cat file
The quick brown fox "jumps", over the 'lazy \"dog\"'
result requested: The quick brown fox jumps, over the 'lazy \"dog\"'
I have seen a working solution for sed, but I like awk
This code seem to work, but for some reason it does remove a blank space after the fox, why?
Code:
awk '{gsub(/[^\\]\"/,x)}1' file
The quick brown foxjump, over the 'lazy \"dog\"'
As far as I understand this means not \ and ", so why is the space gone?
EDIT:
I found why not \ can is any characters but not \, so space is gone and the s in jumps
Any Idea on how to fix this in awk? gensub should work, but not very portable.
---------- Post updated at 13:26 ---------- Previous update was at 12:57 ----------
I found two working version.
Fist is not perfect, but is portable.
Second is less portable.
The quick brown fox "jumps", over the 'lazy \"dog\"' here are some "more data"
it gives
Code:
The quick brown fox jumps, over the 'lazy \"dog\"' here are some more data"
The blue " infront to more is lost.
@pamu
Your fail with both the last " giving
Code:
The quick brown fox jumps, over the 'lazy \"dog\"' here are some more data
Edit: and the my solution fails with this too
Thanks Jotne
Try... for given input this will work
Code:
$ awk '{gsub(/[^\\A-Za-z]\"|"$/," ");gsub(/"\, /,",")}1' file
The quick brown fox jumps,over the 'lazy \"dog\"' here are some more data
OR
Code:
$ awk '{for(i=1;i<=NF;i++)if($i~/^\"|"$/){gsub("\"","",$i);printf $i FS}else{printf $i FS}printf RS }' file
The quick brown fox jumps, over the 'lazy \"dog\"' here are some more data
Last edited by Akshay Hegde; 10-24-2013 at 10:17 AM..
I am hoping to pull multiple strings from one file and use them to search within a block of text within another file.
File 1PS001,001 HLK
PS002,004 MWQ
PS004,002 RXM
PS004,006 DBX
PS004,006 SBR
PS005,007 ML
PS005,009 DBR
PS005,011 MR
PS005,012 SBR
PS006,003 RXM
PS006,003 >SJ
PS006,010... (11 Replies)
Hey Guys,
Earlier I asked a question under Solaris, which I got great help... thanks.
Although I got the script working for what it really needed to do, I am looking for a bit of help to change the output for nicer reading.
my script gets a list of zones under a global-zone and puts this... (4 Replies)
Hi Everybody! First post! Totally noobie.
I'm using the terminal to read a poorly formatted book.
The text file contains, in the middle of paragraphs, hyphenation to split words that are supposed to be on multiple pages. It looks ve -- ry much like this.
I was hoping to use grep -v " -- "... (5 Replies)
Why does this search give different result in awk
I do see a mix of this in the example around the net.
What to use and why?
data
1 = red
2 = green
3 = blue
4 = black
awk '$3 == /blue/' data
"no result"
awk '$3 == "blue"' data
3 = blue
awk '$3 ~ /blue/' data
3 = blue (9 Replies)
Hello All,
I have an Expect script that ssh's to a remote server and runs some commands before exiting.
One of the commands I run is the "hostname" Command. After I run this command I save the output
using this line in the code below...
Basically it executes the hostname command, then I... (2 Replies)
Hi,
I have line in input file as below:
3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL
My expected output for line in the file must be :
"1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL"
Can someone... (7 Replies)
Hi All,
From the title you may know that this question has been asked several times and I have done lot of Googling on this.
I have a Wikipedia dump file in XML format. All the contents are in one XML file i.e. all different topics have been put in one XML file. Now I need to separate them and... (1 Reply)
Hi All,
I'm trying to write a ksh script to parse a file. When the "\" character is encountered, it should be removed and the next line should be concatenated with the current line. For example...
this is a test
line #1\
should be concatenated with line #2\
and line number 3
when this... (3 Replies)
HI Friends,
I am trying to elliminate the " " characters from the word:
"hello" using awk. I need the output to be just = hello (without " " chars). Is there any way to do this ?
Thanks! (3 Replies)
Hi Friends,
Can any of you explain me about the below line of code?
mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`
Im not able to understand, what exactly it is doing :confused:
Any help would be useful for me.
Lokesha (4 Replies)