Awk to Search and Replace inside the pipe "|"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk to Search and Replace inside the pipe "|"
# 1  
Old 02-17-2011
Awk to Search and Replace inside the pipe "|"

Hi,

Anyone can help me on how to replace the qoutes
inside the pipe | in my Text File like belows;

Code:
"AAAA"|"Test "1-A""|"Test AAAA"|"This is A"
"BBBB"|"Test "1-B""|"Test BBBB"|"This is B"
"CCCC"|"My Test C"|"Test "CCCC""|"This is C"

The output I need like belows;
Code:
"AAAA"|"Test 1-A"|"Test AAAA"|"This is A"
"BBBB"|"Test 1-B"|"Test BBBB"|"This is B"
"CCCC"|"My Test C"|"Test CCCC"|"This is C"


Thanks in Advance,
FSPalero

Last edited by Franklin52; 02-17-2011 at 05:31 AM.. Reason: Please use code tags, thank you
# 2  
Old 02-17-2011
AWK
Code:
awk 'gsub("\"\"","\"")' infile

SED
Code:
sed 's/""/"/g' infile

# 3  
Old 02-17-2011
Code:
 $ ruby -i -ne 'print $_.gsub!(/""/,"\"")' file

# 4  
Old 02-17-2011
Code:
sed -i 's/""/"/g' /path/to/file

---------- Post updated at 02:40 AM ---------- Previous update was at 02:39 AM ----------

lol damn...too slow
# 5  
Old 02-17-2011
Quote:
Originally Posted by pravin27
AWK
Code:
awk 'gsub("\"\"","\"")' infile

SED
Code:
sed 's/""/"/g' infile

it the same, giving an output;
Code:
$ awk 'gsub("\"\"","\"")' awk-test.txt
  "AAAA"|"Test "1-A"|"Test AAAA"|"This is A"
  "BBBB"|"Test "1-B"|"Test BBBB"|"This is B"
  "CCCC"|"My Test C"|"Test "CCCC"|"This is C"

Code:
$ sed 's/""/"/g' awk-test.txt
  "AAAA"|"Test "1-A"|"Test AAAA"|"This is A"
  "BBBB"|"Test "1-B"|"Test BBBB"|"This is B"
  "CCCC"|"My Test C"|"Test "CCCC"|"This is C"


Last edited by Franklin52; 02-17-2011 at 05:58 AM.. Reason: Please use code tags
# 6  
Old 02-17-2011
@fspalero @pravin27 @kurumi @DC Slick:

You missed the " which is before the CCCC

Code:
sed 's/"//g;s:|:"|":g;s:.*:"&":' infile


Last edited by ctsgnb; 02-17-2011 at 05:51 AM..
# 7  
Old 02-17-2011
Quote:
Originally Posted by ctsgnb
Code:
sed 's/"//g;s:|:"|":g;s:.*:"&":' infile


hi ctsgnb, It worked like a charm. Thank you.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

grep with "[" and "]" and "dot" within the search string

Hello. Following recommendations for one of my threads, this is working perfectly : #!/bin/bash CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" ) Now I need a grep success for some thing like : #!/bin/bash CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies

2. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

3. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

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)
Discussion started by: shis100
7 Replies

4. Shell Programming and Scripting

Script to search a string which is in between "" and replace it with another character

Hi, I am trying to search a string from a text file which is in between "" (Double Quotes) (Eg: "Unix"), and replace it with a | where ever it is appearing in the text file and save the file. Please help me. -kkmdv (6 Replies)
Discussion started by: kkmdv
6 Replies

5. UNIX for Dummies Questions & Answers

sed for "/7.*" search and replace

Hi , I have this file having thousands of records in it . I want to remove every 9 digit number starting with 7 in it . The few lines from the sample file are "/-GEO-Prizm-Dashes-Covers-Caps-Trim/720000100-200742232-600022761.car"... (8 Replies)
Discussion started by: capri_drm
8 Replies

6. Shell Programming and Scripting

Interesting question - Search and replace the word after sign "="

Hi Guys, Req your help in searching and replacing the word that comes after equals(=) symbol I would like to replace the sting in bold with a string in variable. d=ABCDF8C44C22 # grep -i NIM_MASTERID ${_NIMINFO} export NIM_MASTERID=00CDF8C44C00 I'm looking to replace any word that... (4 Replies)
Discussion started by: ajilesh
4 Replies

7. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

8. Shell Programming and Scripting

awk's getline < "-" seems not work for pipe

Hi all, I have an gawk script to get user's input, So I use getline name < "-" (or getline name < "/dev/stdin") in my script They both work fine when my script deals with files. But it is broken for pipes. When I try "some command | my awk script", the variable name just gets an empty... (17 Replies)
Discussion started by: qiulang
17 Replies

9. Shell Programming and Scripting

Sed , Replace a "variable text" inside of a statement

Please Help... I am trying to manipulte the following line Before : <user:Account_Password>002786</user:Account_Password> the password is the "variable", i need to delete / omit the password in the file, (it occurs several thousand times) so the tag line looks like After:... (4 Replies)
Discussion started by: jackn7
4 Replies

10. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

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)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question