Anders, I see your online, maybe you can answer this fairly quickly for me. I don't use sed very often, how do I shift the first 2 chars of every line to chars 5 & 6. In otherwords if I have lines like: 123456rest of line. I need it to be: 345612rest of line. Reading a tutorial, I think it is something like: sed -e 's@^\(?\)\(?\)\(?\)\(?\)\(?\)\(?\)@\3\4\5\6\1\2@' file I'm going off to try that now. PS: Any tool can be used, but I have 80,000 lines to modify in a single file, and sed is the only tool I know for the job. Thanks Greg -- Greg Freemyer The Norcross Group Forensics for the 21st Century -- Greg Freemyer The Norcross Group Forensics for the 21st Century
On Friday 13 May 2005 00:09, Greg Freemyer wrote:
Anders,
I see your online, maybe you can answer this fairly quickly for me.
I don't use sed very often, how do I shift the first 2 chars of every line to chars 5 & 6.
In otherwords if I have lines like:
123456rest of line.
I need it to be:
345612rest of line.
Reading a tutorial, I think it is something like: sed -e 's@^\(?\)\(?\)\(?\)\(?\)\(?\)\(?\)@\3\4\5\6\1\2@' file
Well, that looks like it might be made to work. This sed -e 's/\(..\)\(....\)/\2\1/' file seems to work when I just tried it.
Anders,
Perfect, thanks a lot.
Your method not only fixes my syntax errors, but is even somewhat
readable. (Assuming any sed script is readable.)
Greg
On 5/12/05, Anders Johansson
On Friday 13 May 2005 00:09, Greg Freemyer wrote:
Anders,
I see your online, maybe you can answer this fairly quickly for me.
I don't use sed very often, how do I shift the first 2 chars of every line to chars 5 & 6.
In otherwords if I have lines like:
123456rest of line.
I need it to be:
345612rest of line.
Reading a tutorial, I think it is something like: sed -e 's@^\(?\)\(?\)\(?\)\(?\)\(?\)\(?\)@\3\4\5\6\1\2@' file
Well, that looks like it might be made to work. This
sed -e 's/\(..\)\(....\)/\2\1/' file
seems to work when I just tried it.
-- Check the headers for your unsubscription address For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com Please read the FAQs: suse-linux-e-faq@suse.com
-- Greg Freemyer The Norcross Group Forensics for the 21st Century
Greg, On Thursday 12 May 2005 15:09, Greg Freemyer wrote:
Anders,
I see your online, maybe you can answer this fairly quickly for me.
I don't use sed very often, how do I shift the first 2 chars of every line to chars 5 & 6.
In otherwords if I have lines like:
123456rest of line.
I need it to be:
345612rest of line.
Reading a tutorial, I think it is something like: sed -e 's@^\(?\)\(?\)\(?\)\(?\)\(?\)\(?\)@\3\4\5\6\1\2@' file
The question mark (?) is a single-character matching wild-card in the shell (and some other contexts). In regular expression contexts (grep / egrep / sed / perl, etc.), the single-character match meta-character is period (.). You don't need to tag (with escaped parentheses) each individual character. You only need to create such tagged sub-matches when you need to individually insert the tagged results into the replacement text. E.g., since your "3456" substring stays in the same order, you could have matched it with \(3456\) and reinserted that substring with a single \1 (or whatever tag ordinal it had in the matching regexp). Note that this is Gnu sed we're talking about, so you can use extended regular expressions, too. E.g., \([3-6]\{4\}\) (a tagged match for exactly 4 repetitions of any of the digits 3 through 6). Lastly, be sure to use the Info documentation to learn about Sed (or some other tutorial information--just be aware that the man page is incomplete for this and many other commands). I find info to be most accessible via Konqueror using the "info:" scheme. E.g., Enter "info:sed" (sans quotes) into a Konqueror address bar and you get a nicely hyperlinked display of the main sed info page.
I'm going off to try that now.
Experimentation is good. Have at it!
... Greg
Randall Schulz
participants (3)
-
Anders Johansson
-
Greg Freemyer
-
Randall R Schulz