LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-23-2009, 08:27 AM   #1
phugoid
LQ Newbie
 
Registered: Mar 2006
Location: Dubai, United Arab Emirates
Distribution: Suse 10.0
Posts: 14

Rep: Reputation: 0
Challenging text manipulation using using sed or alternative


I want to pretty up some output from scripts running RSYNC. I am trying to achieve the following transformation:

Code:
task: syncing directory /var to host 192.168.1.1
cache/g/idx.db
ce/p70/events.hmm
task: syncing directory /tmp to host 192.168.1.100
s/t/eak.fry
Code:
task: syncing directory /var to host 192.168.1.1
192.168.1.1:/var/cache/g/idx.db
192.168.1.1:/var/ce/p70/events.hmm
task: syncing directory /tmp to host 192.168.1.100
192.168.1.100:/tmp/s/t/eak.fry

So you form a string with IP:/dir/ where IP and dir are pulled from headers of the form:
task: syncing directory /dir to host IP
Then you insert that IP:/dir/ string before every filename, on all the lines until the next header is encountered.

By the way, it would be OK to remove the header lines along the way, I'll have to do that anyway.

I can't bend my mind around some of the advanced sed syntax, using the hold buffer. I would be very grateful if you have any idea how to do this.
 
Old 03-24-2009, 01:41 AM   #2
phugoid
LQ Newbie
 
Registered: Mar 2006
Location: Dubai, United Arab Emirates
Distribution: Suse 10.0
Posts: 14

Original Poster
Rep: Reputation: 0
awk

I'm in a bit of a hurry, so I'm answering my own question - it's much easier in AWK, as variables that you define while processing one line of text (record) are available when processing subsequent lines.

Code:
awk '$0 ~  /task: syncing directory / { DIRN=$4; IP=$7 }
     $0 !~ /task: syncing directory / { print IP ":" DIRN "/" $0 }'
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
CSV | Text manipulation lmedland Programming 26 07-31-2008 10:44 AM
Easy string/text manipulation/indentation for restructured text brianmcgee Linux - Software 1 04-22-2008 08:27 PM
need help with text manipulation pcorajr Programming 12 12-15-2006 07:33 AM
Manipulation of text files in C++ Hady Programming 5 05-31-2005 08:24 AM
More text manipulation ice_hockey Linux - General 2 05-28-2005 01:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:25 PM.

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