LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-18-2006, 04:04 PM   #1
User75
LQ Newbie
 
Registered: Apr 2005
Posts: 2

Rep: Reputation: 0
sed headache


Hello people !
After one year of using linux I just began to feel confortable with this OS !!! So I thought it is time to start playing a little with all these linux tools So my problem is that I got stuck with these sed patterns ! My extact problem is that I want to search into a file and find the lines that begin with a W and replace them with a 10char variable which is defined previously in my script ! But I dont want be replaced with 10chars in a row but insteed of it I want my output format to be 2 chars space 2chars space 2chars space etc !!! I guess my sed command would be :

sed "s/^W.*$/$1/g"

It is the $1 that I want to output using the format described above ! I want from you guys , if possible , to guide me for doing this using sed and awk (using sed is my main target) ! Thank you very much
 
Old 06-18-2006, 05:10 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Here is a very good tutorial on sed:

http://www.grymoire.com/Unix/Sed.html#uh-8
 
Old 06-18-2006, 05:13 PM   #3
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
Hi.

Interesting problem.

I'd create a new variable which contains the space separated string (assuming your 10 char variable is called $ten):
Code:
for i in `seq 0 2 8`; do newten="$newten `echo ${ten:$i:2}`"; done
So now you have your space seperated string in $newten to use in your sed command.

I'm sure you can do all this directly in sed, but that's how I'd do it.

Dave

Last edited by ilikejam; 06-18-2006 at 05:15 PM.
 
Old 06-19-2006, 09:15 AM   #4
User75
LQ Newbie
 
Registered: Apr 2005
Posts: 2

Original Poster
Rep: Reputation: 0
Thank you guys ! I will continue searching and I will post the solution here ... if I find any
 
  


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
[sed] "Advanced" sed question(s) G00fy Programming 2 03-20-2006 01:34 AM
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-04-2005 12:00 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 07:12 AM
Help im so new i have a headache jjh221 Linux - Newbie 3 02-11-2004 09:02 PM
headache... katana Linux - General 2 08-02-2001 08:44 AM


All times are GMT -5. The time now is 06:47 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration