Jan 14, 2004 #1 ianicr IS-IT--Management Nov 4, 2003 230 GB I have a file that is: "MR","I","SMITH","1","NEW STREET","LONDON","LONDON" I wish to remove the first london but leave the second. Is there an easy way to do this?
I have a file that is: "MR","I","SMITH","1","NEW STREET","LONDON","LONDON" I wish to remove the first london but leave the second. Is there an easy way to do this?
Jan 14, 2004 #2 SteveR77 Programmer Sep 18, 2000 813 US Question - Given the format of the data being "MR","I","SMITH","1","NEW STREET","LONDON","LONDON" You would want to keep all the data in the case of a record like this one - "MR","R","JONES","1","NEW STREET","GREENWICH","LONDON" Correct? Upvote 0 Downvote
Question - Given the format of the data being "MR","I","SMITH","1","NEW STREET","LONDON","LONDON" You would want to keep all the data in the case of a record like this one - "MR","R","JONES","1","NEW STREET","GREENWICH","LONDON" Correct?
Jan 14, 2004 Thread starter #3 ianicr IS-IT--Management Nov 4, 2003 230 GB Yep. That's just what I need. Not too bothered what goes into the field as long as its not the same as the field after. Upvote 0 Downvote
Yep. That's just what I need. Not too bothered what goes into the field as long as its not the same as the field after.
Jan 14, 2004 #4 Ygor Programmer Feb 21, 2003 623 GB Perhaps use sed.... sed 's/\(,"[^"]*"\)\1/\1/g' file1 > file2 Upvote 0 Downvote
Jan 14, 2004 #5 aigles Technical User Sep 20, 2001 464 FR If you want to remove field 6 ("," separator) if it is the same as field 7 ... with sed : sed -e /s/^\(\([^,]*,\)\{5\}\)\([^,]*\),\3$/\1,\3/' input >output with awk : awk 'BEGIN {FS="," ; OFS=","} $6==$7 {$6=""; print $0}' input >output Jean Pierre. Upvote 0 Downvote
If you want to remove field 6 ("," separator) if it is the same as field 7 ... with sed : sed -e /s/^\(\([^,]*,\)\{5\}\)\([^,]*\),\3$/\1,\3/' input >output with awk : awk 'BEGIN {FS="," ; OFS=","} $6==$7 {$6=""; print $0}' input >output Jean Pierre.
Jan 14, 2004 #6 SteveR77 Programmer Sep 18, 2000 813 US If you need to preserve the field place holder but not the value that it contains you could do the following - sed 's/\(,"[^"]*"\)\1/,""\1/g' file1>file2 Upvote 0 Downvote
If you need to preserve the field place holder but not the value that it contains you could do the following - sed 's/\(,"[^"]*"\)\1/,""\1/g' file1>file2
Jan 14, 2004 #7 PHV MIS Nov 8, 2002 53,708 FR Try this: Code: awk -F, ' $6==$7{$6="\"\""} {print} ' </path/to/inputfile Hope This Help PH. Upvote 0 Downvote
Try this: Code: awk -F, ' $6==$7{$6="\"\""} {print} ' </path/to/inputfile Hope This Help PH.