Visit Our UNIX and Linux User Community


sed usage with special characters - text manipulation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed usage with special characters - text manipulation
# 1  
Old 08-09-2009
sed usage with special characters - text manipulation

I'm trying to use sed to replace string in text file but I've some problems with slash and new-line

for example I have to replace this string:
\> signal_rssi="

or this string where new-line is in the middle of the string:
"
/>



I'm using this code for the first case but it doesn't work:
cat fileIN.txt | sed -e 's/"/\> signal_rssi="/,/' >> fileOUT.txt
...and I've no idea how to do the second



p.s.
files are gps-Kismet-log and I've to substitute string in order to import data in Matlab
# 2  
Old 08-09-2009
it would be better if u give some example from ur inputfile and desired output, and put it in code tags so u can get a quick reply.
# 3  
Old 08-09-2009
Code:
[house@leonov] more test.file
...\> signal_rssi="...
[house@leonov] more test.file | sed 's/\\> signal_rssi="//'
......

Code:
[house@leonov] more test.file
..."
/>...
[house@leonov] more test.file | sed 'N;s/"\n\/>//'
......

# 4  
Old 08-09-2009
Code:
 
cat fileIN.txt | sed -e 's/\\> signal_rssi="/,/' >> fileOUT.txt

For the next one, as mentioned by Malcome, post the input and the expected output. There is not enough details.
# 5  
Old 08-09-2009
Quote:
Originally Posted by malcomex999
it would be better if u give some example from ur inputfile and desired output, and put it in code tags so u can get a quick reply.
I get a partial solution. Now the problem is this one:

fileIN.txt:
Code:
row1
row2
/>
row3
row4
/>
row5

desired fileOUT.txt:
Code:
row1
row2,,,,
row3
row4,,,,
row5

If I use:
Code:
cat fileIN.txt | sed -e 's/\/>//' >> fileOUT.txt

I get this output:
Code:
row1
row2

row3
row4
 
row5

I don't know how to replace empty lines with chars in the line above
may be there is something similar to: sed '/^$/d'


tnx

Last edited by TheMrOrange; 08-09-2009 at 03:38 PM..
# 6  
Old 08-09-2009
Try:

Code:
sed '/\/>/d' file >> fileOUT.txt

# 7  
Old 08-09-2009
Quote:
Originally Posted by Franklin52
Try:

Code:
sed '/\/>/d' file >> fileOUT.txt

may be i'm not using it properly but this code cut all lines bellow the first line that contains />

need to replace delete empty lines and write chars in the line above the line deleted

fileINPUT.txt:
Code:
row1
row2
/>
row3
row4
/>
row5

desired fileOUTPUT.txt:
Code:
row1
row2,,,,
row3
row4,,,,
row5


Previous Thread | Next Thread
Test Your Knowledge in Computers #678
Difficulty: Medium
Wi-Fi positioning systems use the positions of local cellular towers to identify the location of a Wi-Fi device.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove Special Characters Within Text

Hi, I have a "|" delimited file that is exported from a database. There is one column in the file which has description/comments entered by some application user. It has "Control-M" character and "New Line" character in between the text. Hence, when i export the data, this record with the new... (4 Replies)
Discussion started by: tarun.trehan
4 Replies

2. Shell Programming and Scripting

sed in a while loop with special characters

I have the foolowing data file: File1 <p name="A">5004</p> <p name="B">5004</p> <p name="C">5004</p> <p name="A">15004</p> <p name="B">15004</p> <p name="C">15004</p> In a while loop using sed (100 of line need to be replace), I need the output to File3:... (2 Replies)
Discussion started by: bobo
2 Replies

3. Shell Programming and Scripting

Sed - remove special characters

Hi, I have a file with this line, it's always in the first line: I want to remove these special characters: ╗┐ file1 ╗┐\\bar\c$\test2\;3.348.118 Bytes;160 ;3 \\bar\c$\test\;35 Bytes;2 ;1 I want the same file to be only \\bar\c$\test2\;3.348.118 Bytes;160 ;3 \\bar\c$\test\;35... (4 Replies)
Discussion started by: nakaedu
4 Replies

4. Shell Programming and Scripting

sed special characters issue

Hi I'm trying to replace string1 by string2 in file homepage.htm as follows but is not working. Please Help: sedsed -i "s@'://your server name:port/test/owa'@'://11.22.33.44:5555/pls/SAMPLE'@g" homepage.htm Where, String1 ://your server name:port/test/owa String2... (3 Replies)
Discussion started by: koazter
3 Replies

5. Shell Programming and Scripting

Escape special characters in SED

Need help in escaping special characters in sed command. Here is the the string which i am trying to find a replace with From :- REQUEST_TYPE=PIXEL&amp;MSG_ID={//MESSAGE_ID} To :- REQUEST_TYPE=PIXEL&amp;MSG_ID= X_EDELIVERY_MESSAGE_ID &amp; BATCH_ID= X_EDELIVERY_BATCH_ID Here is the sed command i am... (2 Replies)
Discussion started by: aakishore
2 Replies

6. Shell Programming and Scripting

SED with Special characters

Hello All Seeking the right one SED command. My attempt is: From orginal.txt by SED to target.txt sed -i "/('outbound-callerid/a\$ext->add($context, $exten, '', new ext_SipAddHeader('P-Preferred-Identity', '<sip:${CALLERID(nummer)}@carrier.com>'));" orginal.txtWhat am make wrong?:wall: ... (5 Replies)
Discussion started by: mdbinder
5 Replies

7. Shell Programming and Scripting

Using sed to replace special characters

Hi everyone I have file1 contains: '7832' ' 8765 6543 I want a sed command that will format as: '7832' , '8765' , '6543' I tried sed -e s/\'//g -e 's/^*//;s/*$//' file1 > file2 sed -e :a -e '$!N; s/\n/ /; ta' file2 which gives: 7832 8765 6543 I need some help to continue with... (5 Replies)
Discussion started by: nimo
5 Replies

8. Shell Programming and Scripting

sed with many special characters

I started with this: counter1=1 cp file.txt file_${counter1}.tmp while read name1 do echo $name1 counter2=`expr $counter1 + 1` sed /'${name1}'/d file_${counter1}.txt > file_${counter2}.txt counter1=`expr $counter1 + 1` done < source.txtsource.txt contains the... (1 Reply)
Discussion started by: lakanino
1 Replies

9. Shell Programming and Scripting

sed with special characters

Hi, I am reading a file (GC_JAR.log) which has entries like: 511725.629, 0.1122672 secs] 525268.975, 0.1240036 secs] 527181.835, 0.2068215 secs] 527914.287, 0.2884801 secs] 528457.134, 0.2548725 secs] I want to replace all the entries of "secs]" with just "secs" Thus, the output... (4 Replies)
Discussion started by: itzz.me
4 Replies

10. Shell Programming and Scripting

help on sed replacing special characters

Hello, I have a file with many lines with below format: \abc\\1234 jkl\\567 def\\345 \pqr\\567 \xyz\\234 Here, i need to do 2 things. 1. replace \\ with \ 2. remove starting \ so output to be as below: (11 Replies)
Discussion started by: prvnrk
11 Replies

Featured Tech Videos