replace line starting with not a number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting replace line starting with not a number
# 1  
Old 05-16-2012
replace line starting with not a number

Dear users,

I have a file like this:
Code:
geometry,geometry_vertex_count,Id,strnum,platecode,datatype,dtnum,refnum,appearance,disappeara,color,geogdesc,datatype_ft_style,import_notes
"<LineString><coordinates>-130.6539,51.5103,0
-130.7708,51.6287,0
-130.8356,51.6832,0
-130.9211,51.7772,0
-130.9982,51.8414,0
-130.4732,51.3662,0
-130.5872,51.4701,0
-130.6539,51.5103,0</coordinates></LineString>",49,,413,101,TR,1,9829,10.000000,-999.000000,1,TRENCH
BET
JUAN
DE
FUCA
&
N.
AMERICA,0,
"<LineString><coordinates>-106.4797,21.2508,0
-106.4726,21.1354,0
-106.4749,21.0526,0

and I want this:
Code:
>>
>>
-130.7708,51.6287,0
-130.8356,51.6832,0
-130.9211,51.7772,0
-130.9982,51.8414,0
-130.4732,51.3662,0
-130.5872,51.4701,0
-130.6539,51.5103,0</coordinates>
>>
>>
>>
>>
>>
>>
>>
>>
>>
-106.4726,21.1354,0
-106.4749,21.0526,0

Basically, I need to replace all lines that start with a letter or string, except the "-" (i.e. negative number must remain like that).

I tried:
Code:
sed 's/[aA-zZ]/>>/g' file

but doesn't replace the " or ( or other symbols, how could I replace symbols in general? is there a way or should I specify all the symbols?

Thanks in advance,
# 2  
Old 05-16-2012
Hi Gery,

Try with:
Code:
$ cat infile
geometry,geometry_vertex_count,Id,strnum,platecode,datatype,dtnum,refnum,appearance,disappeara,color,geogdesc,datatype_ft_style,import_notes
"<LineString><coordinates>-130.6539,51.5103,0
-130.7708,51.6287,0
-130.8356,51.6832,0
-130.9211,51.7772,0
-130.9982,51.8414,0
-130.4732,51.3662,0
-130.5872,51.4701,0
-130.6539,51.5103,0</coordinates></LineString>",49,,413,101,TR,1,9829,10.000000,-999.000000,1,TRENCH
BET
JUAN
DE
FUCA
&
N.
AMERICA,0,                                                                                                                                                                                                                                   
"<LineString><coordinates>-106.4797,21.2508,0                                                                                                                                                                                                
-106.4726,21.1354,0                                                                                                                                                                                                                          
-106.4749,21.0526,0                                                                                                                                                                                                                          
$ sed -e 's/^[^-].*$/>>/' infile                                                                                                                                                                                                           
>>                                                                                                                                                                                                                                           
>>                                                                                                                                                                                                                                           
-130.7708,51.6287,0                                                                                                                                                                                                                          
-130.8356,51.6832,0                                                                                                                                                                                                                          
-130.9211,51.7772,0                                                                                                                                                                                                                          
-130.9982,51.8414,0                                                                                                                                                                                                                          
-130.4732,51.3662,0                                                                                                                                                                                                                          
-130.5872,51.4701,0                                                                                                                                                                                                                          
-130.6539,51.5103,0</coordinates></LineString>",49,,413,101,TR,1,9829,10.000000,-999.000000,1,TRENCH                                                                                                                                         
>>                                                                                                                                                                                                                                           
>>                                                                                                                                                                                                                                           
>>                                                                                                                                                                                                                                           
>>                                                                                                                                                                                                                                           
>>                                                                                                                                                                                                                                           
>>                                                                                                                                                                                                                                           
>>                                                                                                                                                                                                                                           
>>                                                                                                                                                                                                                                           
-106.4726,21.1354,0                                                                                                                                                                                                                          
-106.4749,21.0526,0

This User Gave Thanks to birei For This Post:
# 3  
Old 05-16-2012
I answer me =), I just did a couple of sed calls:
Code:
sed 's/[Aa-Zz]/>/g' | sed 's/"/>/g' | sed 's/(/>/g' | sed 's/&/>/g'

good enough and efficient, thanks. If anyone has a better way, it's very welcome

---------- Post updated at 05:09 AM ---------- Previous update was at 05:07 AM ----------

WOW, thanks a lot birei, your code works fantastic!!! much better than my way =)

Thanks again.

---------- Post updated at 05:19 AM ---------- Previous update was at 05:09 AM ----------

one more question, with this code I keep the negative numbers:
Code:
sed -e 's/^[^-].*$/>>/'

but in the case I'd have positive numbers, how could I modify it?

Thanks in advance
# 4  
Old 05-16-2012
For also positive numbers use:
Code:
$ sed -e 's/^[^-0-9].*$/>>/' infile

This User Gave Thanks to birei For This Post:
# 5  
Old 05-16-2012
it works perfectly, thanks a lot birei
# 6  
Old 05-18-2012
try this as well

Code:
sed 's/^[^[:digit:]].*/>>/g'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read a file starting at certain line number?

I am new to ksh scripts. I would like to be able to read a file line by line from a certain line number. I have a specific line number saved in a variable, say $lineNumber. How can I start reading the file from the line number saved in $lineNumber? Thanks! (4 Replies)
Discussion started by: dcowboys13
4 Replies

2. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

3. Shell Programming and Scripting

Find and replace in starting of line using sed

Hi, My requirement is, to find the word "data" and replace the starting of each line with # using sed. /dev/datavg/xxx /xxx ext3 defaults 1 2 /dev/datavg/yyy /yyy ext3 defaults 1 2 result to be #/dev/datavg/xxx /xxx ... (1 Reply)
Discussion started by: ksgnathan
1 Replies

4. Shell Programming and Scripting

Replace a field with line number in file

I am working on a script to convert bank data to a csv file. I have the format done - columns etc. The final piece of the puzzle is to change the second field (after the R) of every line to reflect its' line number in the file. I am stumped. I can use awk on each line but need help looping through... (9 Replies)
Discussion started by: Melah Gindi
9 Replies

5. Shell Programming and Scripting

Dynamic number to replace with line

Hi, I have file as below COMMIT # at 34572 # at 23432 COMMIT # at 5674 # at 7856 I want to replace with as below (12 Replies)
Discussion started by: kaushik02018
12 Replies

6. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

7. Shell Programming and Scripting

Replace first number of each line in a file with another number

Hi, I have a set of files in a directory that I have to read and replace the first occurrence of a number with another dummy number. This is what I have so far but it does not seem to work. The files have lot of other data in each row and each data element is separated by ,@, for file in... (13 Replies)
Discussion started by: scorpioraghu
13 Replies

8. Shell Programming and Scripting

replace blank line number

hlow all i need help how can i replace blank number with awk input.txt 300::|355264313178490 301::|358814003239510 302::|358316038113400 303::|357954002633660 304::|354072040694090 305::|356956015214190 306::|352943020525180 307::|359574033836610 308::|381810990023580 so will be like... (4 Replies)
Discussion started by: zvtral
4 Replies

9. Shell Programming and Scripting

SED: Place char at starting and replace selected line

Hello Experts, I am working on a small file editing script. Since all experts here are very generous to give me the complete code, I would take up the problem in steps so that I ensure my opportunity to learn. AIM: The script has some commented and some uncommented lines. I need to : ... (2 Replies)
Discussion started by: hkansal
2 Replies

10. UNIX for Dummies Questions & Answers

shell script to replace a line contain an unkown pattern starting with "aaa, bbb"

Hello, can any one help me on this? I have a /etc/exports file, it may contain a line (I can not remember exactly). Let me use an a sample file myfile.txt which contains a line * mypattern uncertain key words I want this line (with any possible combination of the uncertain key words to be... (2 Replies)
Discussion started by: Dingrong
2 Replies
Login or Register to Ask a Question