LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 03-24-2008, 04:54 AM   #1
joyds219
LQ Newbie
 
Registered: Mar 2008
Posts: 9

Rep: Reputation: 0
Question Help on using SED


I am trying to make a customized build. The case is that in the ACTUAL file the line no. 25 has all key word names(shown in bold) and that is to be replaced with only SPECIFIC key words from a db file named name.db file with remaining contents unchanged and the desired output can be seen in the OUTPUT file wherein the line no. 25 now contains key words of only those names present in .db file. Please refer to Case Example Below
Note: I would like to use mostly the SED command for that purpose.
Eg.
name.db contains key words

Code:
EXA
TOR
EDG
PLAT
CLUT
FIT
SHER
CUT
OPTI
REM
ACTUAL File


25PreprocessorDefinitions="NDEBUG;NEST_WIN;EXA;TOR;malloc=nest_malloc;free=nest_free;EDG;PLAT;CLUT;FIT;SHER;CUT;OPTIMI;WIN32;_WINDOWS;MSVC;NO_SENTINEL_LOCK;LEAT;SPD;OPTI;REM;FORE;DOTNET;SNP"

Expected OUTPUT File



PreprocessorDefinitions="NEST_WIN;EXA;TOR;malloc=nest_malloc;free=nest_free;EDG;PLAT;CLUT;FIT;SHER;CUT;OPTI;WIN32;_WINDOWS;MSVC;NO_SENTINEL_LOCK;REM;DOTNET"

Is there a solution for this?

Last edited by joyds219; 03-25-2008 at 11:34 AM. Reason: add code tags
 
Old 03-25-2008, 12:27 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Sorry, I don't follow. I still see heaps of stuff in both line's 25 that
isn't part of your name.db file? Either your sample data or your explanation
of what you're trying to achieve are lacking.



Cheers,
Tink


P.S.: I took the liberty to slap code-tags into your post - it was
initially so wide that it was too hard to read to be fun ;}
 
Old 04-04-2008, 11:39 AM   #3
joyds219
LQ Newbie
 
Registered: Mar 2008
Posts: 9

Original Poster
Rep: Reputation: 0
ok I shall simplify it further.

PreprocessorDefinitions="NDEBUG;NEST_WIN;malloc=nest_malloc;free=nest_free;WIN32;_WINDOWS;MSVC;NO_SE NTINEL_LOCK;EXA;TOR;LEAT;SPD;OPTI;REM;FORE;DOTNET;SNP;EDG;PLAT;CLUT;FIT;SHER;CUT;OPTIMI"


replace the part in bold with the contents from other file name.db as shown above using sed or grep

the output should be as below

PreprocessorDefinitions="NDEBUG;NEST_WIN;malloc=nest_malloc;free=nest_free;WIN32;_WINDOWS;MSVC;NO_SE NTINEL_LOCK;EXA;TOR;EDG;PLAT;CLUT;FIT;SHER;CUT;OPTI:REM"

Last edited by joyds219; 04-04-2008 at 11:43 AM.
 
Old 04-04-2008, 03:00 PM   #4
prad77
Member
 
Registered: Mar 2008
Posts: 101

Rep: Reputation: 15
I used cut command and concatenate with namedb.

newdef1=`echo $PreprocessorDefinitions | cut -d 'EXA' -f1 `

So your unwanted extensions are out. Now....

namedbvar=`cat namedb`
newdef2=${newdef1}${namedbvar}

Dont forget to complie and adjust it further to ur needs.

Gentoo

Last edited by prad77; 04-17-2008 at 04:41 AM.
 
Old 04-04-2008, 04:33 PM   #5
beadyallen
Member
 
Registered: Mar 2008
Location: UK
Distribution: Fedora, Gentoo
Posts: 209

Rep: Reputation: 36
I'm assuming the ordering of the definitions isn't important. If that's the case, I'd have two files, one containing ALL definitions possibly needing replacing, and then have another file with the ones you want. Strip out everything, than append the ones you want:
Code:
ALLDEFS=`cat all_possible_defs.db`
NEWDEFS=`cat names.db`
for x in $ALLDEFS
do
   PreprocessorDefinitions=`echo "$PreprocessorDefinitions" \
   | sed "s/$x\;//"`
done

for x in  $NEWDEFS
do
   PreprocessorDefinitions="$PreprocessorDefinitions$x\;"
done
This way you don't have to worry about 'cutting' things out you might be unable to replace. Not sure if it's what you want though.
 
  


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
filter out lines containing specific keywords from output kpachopoulos Linux - General 2 03-12-2007 09:29 PM
php - Read file line by line and change a specific line. anrea Programming 2 01-28-2007 02:43 PM
GCC 4.0 specific keywords abk4523 Programming 1 09-22-2005 01:03 PM
Substitute String or line in a file dimsh Linux - Newbie 4 09-21-2005 04:26 AM
Printing a specific line charlie123 Linux - Newbie 2 02-10-2003 11:59 AM


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