Remove Colons and Slashes from 2nd Token


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Remove Colons and Slashes from 2nd Token
# 1  
Old 03-15-2011
Remove Colons and Slashes from 2nd Token

I would prefer to use Sed, but I will do whatever necessary. I want to know a good way to remove ":" and "/" from the first string surrounded in Double quotes, but not the 2nd.

Current File:
Code:
"9781238274584-Ace of Spades: The Poop" "Ace of Spades: The Poop" ...

Desired:
Code:
"9781238274584-Ace of Spades The Poop" "Ace of Spades: The Poop"  ...

---------- Post updated 03-15-11 at 10:11 AM ---------- Previous update was 03-14-11 at 06:07 PM ----------

Nobody can recommend a way to remove a colon or slash between the first set of double quotes, but leave the string in the second and third sets of quotes alone?

Last edited by glev2005; 03-14-2011 at 09:24 PM..
# 2  
Old 03-15-2011
Code:
echo '"9781238274584-Ace of Spades: The Poop" "Ace of Spades: The Poop" ...' |  sed 's#[:/]##1'

This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 03-15-2011
Good idea vgersh! I don't know why I didnt think of that. I guess I am concerned that it would affect parts of the file where colons or slashes exist outside of double quotes.. Any way to make this work only on strings that are enclosed in double quotes? I can figure it out probably. I'm guessing to use a regex in the sed command to denote that [:/] needs to be in double quotes.
# 4  
Old 03-15-2011
Code:
echo 'foo:"9781238274584-Ace of Spades/ The Poop" "Ace of Spades: The Poop" ...' | sed 's#"\([^"]*\)[:/]\([^"]*\)"#"\1\2"#1'

This User Gave Thanks to vgersh99 For This Post:
# 5  
Old 03-15-2011
Sorry but what if there are more than one colon or slash in between the first set of quotes?
# 6  
Old 03-15-2011
nawk -f glev.awk qq='"' myFile
glev.awk:
Code:
{
  if (match($0, qq "[^" qq "]+" qq)) {
     s=substr($0,RSTART,RLENGTH)
     gsub("[:/]", "",s)
     $0=substr($1,1,RSTART-1) s substr($0,RSTART+RLENGTH)
  }
}
1

This User Gave Thanks to vgersh99 For This Post:
# 7  
Old 03-15-2011
Try this:

awk -F'"' '{gsub("[:/]","",$2); print $0; }' myFile
This User Gave Thanks to 116@434 For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk command 2nd col remove the '-' value

Hi, i was tried using the awk command for replacing '-' in the second column. but the below command replacing the entire file. cat 1.txt |awk '{gsub(/-/,"")}1' Input file 1,2,3,-4,5,6 1,-2,3,4,5,-6 1,2,3,4,5,6 1,-2,3,4,-5,6 Output file 1,2,3,-4,5,6 1,2,3,4,5,-6 1,2,3,4,5,6... (3 Replies)
Discussion started by: onesuri
3 Replies

2. Programming

Print slashes using C

I want to print 4052 slashes using this C program. #include <stdio.h> void main() { int i; for (i=0; i<4052; i++) printf ("/"); } When i compile this via gcc am getting this error : http://gyazo.com/e0403e4789575d181d1695f9db3e6d6e.png Can anyone point out what am doing wrong? (15 Replies)
Discussion started by: vish6251
15 Replies

3. Shell Programming and Scripting

remove values of a file one by one from 2nd file and then print the remaining values of 2nd file

Hi all, I have 2 files. One contains only 1 column and other one contains 2 columns, let say 1_col.txt and 2_col.txt respectively. Here, I will try to explain with an example. Input files : 1_col.txt 2_col.txt a a b x a c p ... (5 Replies)
Discussion started by: AshwaniSharma09
5 Replies

4. Shell Programming and Scripting

Remove leading zeroes in 2nd field using sed

Hi Forum. I tried searching the forum but couldn't find a solution for my question. I have the following data and would like to have a sed syntax to remove the leading zeroes from the 2nd field only: Before: 2010-01-01|123|1|1000|2000|500|1500|600|700... (18 Replies)
Discussion started by: pchang
18 Replies

5. Shell Programming and Scripting

sed - how to remove trailing slashes

I know you can remove trialing slashes using: #echo "/tmp/one/two/three////" | sed "s,/$,," /tmp/one/two/three/// But I want to know how to make it remove all trialing flashes in the front, and in the start, so the end result is: tmp/one/two/three Anyone have any idea how to do this... (6 Replies)
Discussion started by: EXT3FSCK
6 Replies

6. Shell Programming and Scripting

remove colons in MAC address

whats the simplest method to remove the colons from a mac address in PERL? thanks & regards (3 Replies)
Discussion started by: hazno
3 Replies

7. UNIX for Dummies Questions & Answers

Need Script to insert colons in each line of file

I have a file with over 500 MAC addresses. Each address is on a new line. However, the MACs do not have ":" I need a script that will read the file, line by line and insert colons in the addresses and then print the results to a new file. current.txt looks like this 111111111111 222222222222... (4 Replies)
Discussion started by: canopus15
4 Replies

8. UNIX for Dummies Questions & Answers

dots and slashes

when I execute a command in like "run.sh," I can run it two ways: ./run.sh or . run.sh What is the difference? (1 Reply)
Discussion started by: DarkLord
1 Replies

9. Shell Programming and Scripting

Need to add colons

Hey guys i need to take the MAC address in the format of 0x00255T08D433 and convert it to 00:25:5T:08:D4:33 (it goes :08: D4:33 with no space the forum is making it a big smiley) for a script i am working on. I am Not quite sure where to start with this one any help would be... (4 Replies)
Discussion started by: insania
4 Replies

10. UNIX for Dummies Questions & Answers

One or two colons with rsync?

I was reading about the different ways to run rsync. It looks like connecting to an rsync deamon is very similar to connecting to an rsync shell like ssh. Are there situations where the deamon is superior to the ssh? Are there situations where ssh is superior to the deamon? Thanks,... (0 Replies)
Discussion started by: siegfried
0 Replies
Login or Register to Ask a Question