Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 06-18-2006, 03:04 PM   #1
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, 04:10 PM   #2
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:
Old 06-18-2006, 04:13 PM   #3
Senior Member
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96

Interesting problem.

I'd create a new variable which contains the space separated string (assuming your 10 char variable is called $ten):
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.


Last edited by ilikejam; 06-18-2006 at 04:15 PM.
Old 06-19-2006, 08:15 AM   #4
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


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

All times are GMT -5. The time now is 12:05 AM.

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