Replacing Characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing Characters
# 8  
Old 09-12-2008
I cannot use the character ~ as this might come in the data.....
Any other suggestions i tried all of the above none seems to work
# 9  
Old 09-12-2008
Hi Era your solution worked fine with using sed "s/'/'\\
/g" file

however i am not sure how to use these two commands in the command

remoteName=ediweb$(date +%m%d%H%M%S).$(cat $localFromDir/$currentFile | tr -d '\012' | tr \' '\012' | grep ^UNB | head -1 | cut -d+ -f6)

can you please let me know how can i replace your command with the one tr \' '\012' mentioned in my above command

thanks

karan
# 10  
Old 09-12-2008
If I grok the above command soup correctly, you want

Code:
remoteName=ediweb$(date +%m%d%H%M%S).$(tr -d '\012' <$localFromDir/$currentFile | sed "s/'/'\\
/g" | grep ^UNB | head -1 | cut -d+ -f6)

That's still pretty useless, as you could replace the whole sed | grep | head mess with a single sed script.

Code:
remoteName=ediweb$(date +%m%d%H%M%S).$(tr -d '\012' <$localFromDir/$currentFile |
    sed -n "s/\(.*'\)\?\([^']*UNB[^']*'\).*/\1/p;T;q" | cut -d+ -f6)

The cut could probably also be added to the sed script, and the tr might be unnecessary, depending on the input file format.
# 11  
Old 09-12-2008
Can you explain me briefly what exactly the whole sed command that you have written is doing???

thanks

Karan
# 12  
Old 09-12-2008
i tried using the above it didnt run and gave me an error:-

sed:0602-403 then whole command is not a recognised function
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed replacing specific characters and control characters by escaping

sed -e "s// /g" old.txt > new.txt While I do know some control characters need to be escaped, can normal characters also be escaped and still work the same way? Basically I do not know all control characters that have a special meaning, for example, ?, ., % have a meaning and have to be escaped... (11 Replies)
Discussion started by: ijustneeda
11 Replies

2. Shell Programming and Scripting

Echo is replacing characters

Hi All, I'm using KSH and am writing a small script that counts the lines of various files in several folders under one root folder. Below is the script: #!/usr/bin/ksh common_path_in="/interface_in/rsc" file_out="/interface_in/rsc/record_count.csv" tot_rec_count=-1 act_rec_count=-1... (5 Replies)
Discussion started by: jagari
5 Replies

3. Shell Programming and Scripting

Replacing junk characters

Hi, I have a file with data as given below $cat file1 123|abc|345 345|def|567 The first record is good record. The second record has an invisible junk character like \032. I was replace all the occurences of that invisible character with #. I want to do this for a set of... (16 Replies)
Discussion started by: ashwin3086
16 Replies

4. Shell Programming and Scripting

Replacing characters

Hi fellow experts, I have a question for you. Data looks like: 00877,05/13/2010,PBO,P,0000708331,518 00877,05/13/2010,PBO,P,0000708331,519 ... ... 00877,05/13/2010,PBO,P,0000708331,2103 00877,05/13/2010,PBO,P,0000708331,2104,etc,etc Basically I have to replace 518,519,2103,2104,... (4 Replies)
Discussion started by: Devski123
4 Replies

5. Shell Programming and Scripting

Replacing Characters with |

Hi All, example data.log 526569346 66815531961 09 526569346 66815531961 09 526569346 66815531961 09 526569346 66815531961 09 526569346 66815531961 09 I want like this to 526569346|66815531961|09 526569346|66815531961|09... (4 Replies)
Discussion started by: ooilinlove
4 Replies

6. Shell Programming and Scripting

replacing characters

hi all I have a file that has sone spaces in start then / at last. i want to get rid of this. how to do? eg. 11414/ 49878/ 27627/ I WANT THE FILE AS 11414 49878 27627 PLEASE HELP (3 Replies)
Discussion started by: infyanurag
3 Replies

7. UNIX for Dummies Questions & Answers

replacing the characters in a file

hi i want to replace the characters between positions 2 to 30 in each line in a file how to do it suggestions welcome (2 Replies)
Discussion started by: trichyselva
2 Replies

8. UNIX for Dummies Questions & Answers

replacing characters

Hi, I have a script for replacing bad characters in filenames for f in *; do mv $f `echo $f | tr '+' '_'` done; this replaces + for _ But I need to replace all bad characters ? / % + to _ Pls how can i do this in one script ? (3 Replies)
Discussion started by: palmer18
3 Replies

9. Shell Programming and Scripting

replacing certain characters with new line?

i have a text file which domains something like this 123213213213/32434342 324324324/12312321321 12321321,435435435 12321312 / 12313213 / 12435435345 4353213 , 123213213213 21321321312-12334324 234324324 - 235645645645 456456456 - 45456456456 - 45645645654243 how can i replace '/' and... (4 Replies)
Discussion started by: Bashar
4 Replies

10. UNIX for Dummies Questions & Answers

replacing few characters in a file

Hi All, I have huge xml file. The file contains some comment tags . I have requirement to replace comment tag with another comment tag. Say for example : file X has -- Part of the file <?xml version="1.0" encoding="ISO-2"?><translationResults jobDate="20070123 23:20:51"... (1 Reply)
Discussion started by: purnakarthik
1 Replies
Login or Register to Ask a Question