LinuxQuestions.org
Review your favorite Linux distribution.
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
 
LinkBack Search this Thread
Old 11-18-2009, 05: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, 06:22 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Location: the Netherlands
Distribution: lfs, debian, rhel
Posts: 7,009
Blog Entries: 2

Rep: Reputation: Disabled
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are 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 06:30 PM
extracting emails from file using regular expressions in php on linux sriphp Linux - Software 3 09-14-2009 04:34 AM
LXer: Learn Regular Expressions the easy way in Linux LXer Syndicated Linux News 0 01-27-2006 09:46 AM


All times are GMT -5. The time now is 12:04 PM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration