Visit Our UNIX and Linux User Community


delete " from plain text files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting delete " from plain text files
# 1  
Old 08-28-2009
delete " from plain text files

Hi,
sorry for bothering with this easy problem but I can't understand...

I've a file like this:
Code:
"4","0x23a3"
"5","0x4234"
"11",""
"20",""
"11132","0x6456"

I would like to create a file like this:
Code:
4,23a3
5,4234
11,999999
20,999999
11132,6456

I've tried:
Code:
cat INPUT.txt | sed -e 's/0x//' -e 's/""/999999/' -e 's/"//' >> OUTPUT.txt

but I've obtained this:
Code:
4","23a3"
5","4234"
11",999999
20",999999
11132","6456"

there are two problems:
why
Code:
-e 's/"//'

can not delete all
Code:
"

?
why script create an empty line at the end of the OUTPUT.txt file ?

Thank a million
# 2  
Old 08-28-2009
Code:
sed -e 's/0x//' -e 's/""/999999/' -e 's/"//g' INPUT.txt

# 3  
Old 08-28-2009
use this

's/\"//'
# 4  
Old 08-28-2009
Quote:
Originally Posted by kd09714
use this

's/\"//'
why is that?
# 5  
Old 08-28-2009
>cat abc
"4","0x23a3"
"5","0x4234"
"11",""
"20",""
"11132","0x6456"

>sed -e 's/0x//g' -e 's/""/999999/' -e 's/\"//g' abc
4,23a3
5,4234
11,999999
20,999999
11132,6456
# 6  
Old 08-28-2009
Code:
's/"//g'
's/\"//g'

both work... tnx

anyway I still have a new empty line at the end of my output file... do you have any idea?
# 7  
Old 08-28-2009
Quote:
Originally Posted by kd09714
>cat abc
"4","0x23a3"
"5","0x4234"
"11",""
"20",""
"11132","0x6456"

>sed -e 's/0x//g' -e 's/""/999999/' -e 's/\"//g' abc
4,23a3
5,4234
11,999999
20,999999
11132,6456
why do you need to escape a double quote?
and don't escape TWO double quotes?
Code:
sed -e 's/0x//g' -e 's/""/999999/' -e 's/\"//g' abc



---------- Post updated at 05:14 PM ---------- Previous update was at 05:09 PM ----------

Quote:
Originally Posted by TheMrOrange
Code:
's/"//g'
's/\"//g'

both work... tnx

anyway I still have a new empty line at the end of my output file... do you have any idea?
either:
  • you had an empty line in the original file
  • you had a single double-quote in the original file AND 'sed' substituted to nothing in the 'last' expression

Code:
sed -e 's/0x//g' -e 's/""/999999/' -e 's/"//g' -e '/^ *$/d' abc


Previous Thread | Next Thread
Test Your Knowledge in Computers #964
Difficulty: Medium
HTML4 became a W3C Recommendation in 1994.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies

2. Shell Programming and Scripting

Modify one line in a plain text file

Hi everyone, I want to know, if there is a way to modify one line in a text file with unix script, with out re-writing all the file. For example, i have this file: CONFIGURATION_1=XXXX CONFIGURATION_2=YYYY CONFIGURATION_3=ZZZZ supose i have a command or function "modify" that... (7 Replies)
Discussion started by: Xedrox
7 Replies

3. Homework & Coursework Questions

how to change this looking for mimetype "text/plain" instead of extension *.txt?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Create a Shell script that looks for all text files in your home directory (including subdirectories). List... (3 Replies)
Discussion started by: rollinator
3 Replies

4. Shell Programming and Scripting

from one word for line to plain text

Hello! I've got a very big file (from tokenization) which has one word for line. How is it possible then to rebuild the "original" text, knowing that <s> and </s> are the sentence-delimiters? My file looks like this: <s> && tanzania na Afrika kwa ujumla ambiwa na taifa kubwa... (6 Replies)
Discussion started by: mjomba
6 Replies

5. Shell Programming and Scripting

Delete files older than "x" if directory size is greater than "y"

I wrote a script to delete files which are older than "x" days, if the size of the directory is greater than "y" #!/bin/bash du -hs $1 while read SIZE ENTRY do if ; then find $1 -mtime +$2 -exec rm -f {} \; echo "Files older than $2 days deleted" else echo "free Space available"... (4 Replies)
Discussion started by: JamesCarter
4 Replies

6. Shell Programming and Scripting

Script for delete tmp files older than 15 days and owned by "xxx" id

Hi All , I want to delete files from /tmp directory created by "xxxx" id. because i got the list says more than 60 thousand files were created by "xxxx" id since 2002. The /tmp directory has lot of files created by different user ids like root,system etc.. But, i need a script to... (2 Replies)
Discussion started by: vparunkumar
2 Replies

7. Shell Programming and Scripting

Unix commands delete all files starting with "X" except "X" itself. HELP!!!!?

im a new student in programming and im stuck on this question so please please HELP ME. thanks. the question is this: enter a command to delete all files that have filenames starting with labtest, except labtest itself (delete all files startign with 'labtest' followed by one or more... (2 Replies)
Discussion started by: soccerball
2 Replies

8. Shell Programming and Scripting

Sed: Delete lines in files that contain other than a-z ,0-9 and "."

Sed: Delete lines in files that contain other than 'a-z' ,'0-9', '.' and '-' Hello, I'm looking for a shell command or maybe a small php loop to delete lines in files.txt (in the same directory) that contain character other then 'a-z' ,'0-9', '.' and '-' All line that have characters like... (4 Replies)
Discussion started by: devlin
4 Replies

9. Linux

Plain Text printing issues

I'm attempting to print to a networked konica printer. No linux drivers that I know of exist, but we've always used HP 5si drivers and have had good results. We just loaded a box up with CentOS 5, and now when we print any sort of file from the command line (lp -dkonica <filename>), the text is... (0 Replies)
Discussion started by: fender177
0 Replies

10. AIX

email from root sent my passord in plain text.

Root emailed me this message and thats ok it is supposed to. The thing that concerns me is that the ADMIN password came in plain text. I Xed it out for the purpose of this message of course. Is there a way for me to set this so the password comes encrypted? OR is not included at all in the... (4 Replies)
Discussion started by: rocker40
4 Replies

Featured Tech Videos