• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

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

WarDemon666

Platinum Member
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!!
 
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!!
 
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.
 
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.
 
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
 
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?
 
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" 😛
 
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:
 
Back
Top