LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-18-2009, 04:58 AM   #1
Alex_is
LQ Newbie
 
Registered: Nov 2009
Posts: 3

Rep: Reputation: 0
editing with regular expressions in linux?


if i have created a file consisting of lines, with say four words per line separated by a space, andsay i typed this command into vi;

:%s/\(\a\+\)\s*\(\a\+\)\s*\(\a\+\)\s*\(\a\+\)/\4-\3-\2-\1/

what would this command do to the file and how would it work exactly. i am very new to linux and have tried to understand the question but cannot. i dont have access to a linux machine until next week so cant try it. plz help!
 
Old 11-18-2009, 05:22 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

First: This looks a lot like homework to me, so I'll just give a partial answer. It is up to you to figure out how this command works.

The end result will be: the four words in reverse with a dash (-) in between.

aaaaa bbbbb ccccc ddddd -> ddddd-ccccc-bbbbb-aaaaa

Take a look at this sed page, it holds all the answers you are looking for:
sed tutorial

Hope this helps.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Finding Things on Linux and Understanding Regular Expressions LXer Syndicated Linux News 0 09-14-2009 05:30 PM
extracting emails from file using regular expressions in php on linux sriphp Linux - Software 3 09-14-2009 03:34 AM
LXer: Learn Regular Expressions the easy way in Linux LXer Syndicated Linux News 0 01-27-2006 08:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration