Question about linux: Stream edit (SED)... can someone help?

WarDemon666

Platinum Member
Nov 28, 2000
2,224
0
0
Lets say i have this data:

123
1245
265
sgdfg
bla
4235
sdaf
sag
smdm
sklmdsf
kmsd
bla2

I want to move bla2 to where bla is, and bla where bla2 is...

if i use sed -e '/bla/h' -e '/bla2/x' DATAFILE it changes the last one to bla...

is there a way to exchange the two lines?

Thanks in advance!!
 

WarDemon666

Platinum Member
Nov 28, 2000
2,224
0
0
Originally posted by: sao123
use c++.... much easier.

im trying to get used to sed.. I know theres a way to do it....

somehow ill have to read it into a file and hold buffer also.... someone help!!
 

urname7698

Senior member
Feb 2, 2004
479
0
0
try something like sed s/bla2/voovoo/g | sed s/bla/bla2/g | sed s/voovoo/bla/g

does that make sense?
 

fs5

Lifer
Jun 10, 2000
11,774
1
0
Originally posted by: sao123
use c++.... much easier.

for text processing such as this, sed is much faster for people that know how to use it. As for me, I never learned but should.
 

randal

Golden Member
Jun 3, 2001
1,890
0
71
I don't know a whole lot about sed, but I do know that you can grab the line numbers you are working on with `grep -n "text_to_find" file` ...

If you are looking for pairs, you could do this ...

grep -n "text_a" file >> output
grep -n "text_b" file >> output
cat output | cut -f1 -d: | sort -n

That will spit out the line numbers, in order, of things that match. If somebody has a line-switching script, then with a little coding you should be set.
 

randal

Golden Member
Jun 3, 2001
1,890
0
71
Originally posted by: urname7698
try something like sed s/bla2/voovoo/g | sed s/bla/bla2/g | sed s/voovoo/bla/g

does that make sense?

I took this on as a challenge for lunch, and came up with a terrible way to do it with awk, a not-working way to do it with perl, and the following sed script which works -- urname was right on.

sed -e 's/^bla$/something_else/g' -e 's/^bla2$/bla/g' -e 's/something_else/bla2/g' your_file
 

WarDemon666

Platinum Member
Nov 28, 2000
2,224
0
0
Originally posted by: randal
Originally posted by: urname7698
try something like sed s/bla2/voovoo/g | sed s/bla/bla2/g | sed s/voovoo/bla/g

does that make sense?

I took this on as a challenge for lunch, and came up with a terrible way to do it with awk, a not-working way to do it with perl, and the following sed script which works -- urname was right on.

sed -e 's/^bla$/something_else/g' -e 's/^bla2$/bla/g' -e 's/something_else/bla2/g' your_file

I forgot to add something here. I want the whole line, and each line contains garbage, we dont know what each line has...

meaning, theres not ONLY bla on the line.... your ^bla$ represents only that on the line....

ideas to move the whole line?
 

fs5

Lifer
Jun 10, 2000
11,774
1
0
Originally posted by: WarDemon666
I forgot to add something here. I want the whole line, and each line contains garbage, we dont know what each line has...

meaning, theres not ONLY bla on the line.... your ^bla$ represents only that on the line....

ideas to move the whole line?
it's as if WarDemon666 were sales and ATOT is engineering. "Oh by the way, I forgot to mention we wanted this feature also... not that it would have helped you if you knew the specs from the beginning"
 

WarDemon666

Platinum Member
Nov 28, 2000
2,224
0
0
Originally posted by: fs5
Originally posted by: WarDemon666
I forgot to add something here. I want the whole line, and each line contains garbage, we dont know what each line has...

meaning, theres not ONLY bla on the line.... your ^bla$ represents only that on the line....

ideas to move the whole line?
it's as if WarDemon666 were sales and ATOT is engineering. "Oh by the way, I forgot to mention we wanted this feature also... not that it would have helped you if you knew the specs from the beginning"

lol.... sorry about that

:thumbsup:
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |