regex


move a pattern to the beginning of a line with sed


how can i move a pattern to the beginning of the line?
1702,1833,09C4,098C:325F|Sky|sportdigital|TV|Sky sonstige
should be
325F:1702,1833,09C4,098C|Sky|sportdigital|TV|Sky sonstige
i figured out that i can insert a char or a word to the beginning when my pattern is found. but i don't get it to move my searched pattern...
sed -r '/(:325F)/ s/^/#/'
this puts a "#" to the beginning when my pattern ":325F" is found.
when i do this: sed -r '/(:325F)/ s/^/\1/' it gives me an error...
has anyone some tips to get me in the right direction?
br
chris
You directly use find and replace in sed.
sed 's/^\([^:]*\):\([^|]*\)/\2:\1/' file
Example:
$ echo '1702,1833,09C4,098C:325F|Sky|sportdigital|TV|Sky sonstige' | sed 's/^\([^:]*\):\([^|]*\)/\2:\1/'
325F:1702,1833,09C4,098C|Sky|sportdigital|TV|Sky sonstige
$ echo '1702,1833,09C4,098C:325F|Sky|sportdigital|TV|Sky sonstige' | sed 's/^\([^:]*\):325F/325F:\1/'
325F:1702,1833,09C4,098C|Sky|sportdigital|TV|Sky sonstige

Related Links

Extract resolution from string
How do I create a Scala Regex that is compiled using Java Pattern.COMMENTS?
Is there a way to search terms in order with RegexpQuery in lucene?
Regex to allow any charcter EXCEPT backslash
Regex: Match a condition, then find the first occurrence of another condition that precedes it on the same line. Possible?
Regex for URL routing - match alphanumeric and dashes except words in this list
R: gsub and capture
Trouble with regex in Perl
Duplicate symbols in regular expressions
NSRegularExpression to remove the rest codes
Regex replace in sublimetext2
Regular Expression Search Replace all non leading tabs with single space Notepad++
Django regular expression on success format
Reg ex required for finding two ||
regex from first character to the end of the string
How can I recognize the following group of strings using a grammar or regex?

Categories

HOME
x-editable
path
libreoffice
visual-studio-2012
apple-mail
add-in
telnet
calayer
openframeworks
sqlconnection
coreos
cloudrail
export-to-excel
monaco-editor
next
flow
zap
gyroscope
exe4j
rtp
aspdotnetstorefront
polynomials
wso2cep
symbolic-math
liferay-aui
google-oauth2
weather-api
code-signing
operator-keyword
kprobe
ruamel.yaml
seh
atlassian-bitbucketserver
dxgi
php-5.5
angularjs-routing
quicksand
zfs
couchbase-lite
federation
sharpziplib
ganglia
replaygain
unityscript
ietf-netconf
ice
biological-neural-network
ifc
mailcore2
evaluate
visual-build-professional
4d
activemodel
mutation
vimeo-ios
xlform
screen-capture
jni4net
subroutine
materialdrawer
sejda
folder-structure
kindlegen
node-orm2
dhc
alt
movie
kue
misra
brooklyn
fig
dirpagination
android-c2dm
antisamy
nawk
simpleaudioengine
vlfeat
location-client
bochs
libnids
flash-cs4
flexpaper
src
hamlc
jcycle
browserid
squirrelmail
mknetworkkit
cellphone
httpconnection
gemstone
duplicate-data
jtemplates
rails-3.1
gumstix
palm-pre

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App