LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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

View Poll Results: Do you think it is Complicated?
yes 0 0%
no 3 100.00%
Voters: 3. You may not vote on this poll

Reply
 
Search this Thread
Old 03-18-2008, 07:11 AM   #1
joyds219
LQ Newbie
 
Registered: Mar 2008
Posts: 9

Rep: Reputation: 0
Question Please explain the following script


hi,

Can anyone please explain to me what does this command in bold do. I am a beginner in unix & i somewhat know that sed can be used for replacement purposes;but i am unable to understand the 2 SED statements in the scripas to what is being performed. please help me understand in detail if possible as shell scripting is new to me.



# INPUT DATA

INP_FILE=E:/Testrel/nest/nestlib/build/winlib/WinLib.ORG
OUT_FILE=E:/Testrel/nest/nestlib/build/winlib/WinLib.dsp

ALLMOD_LIST=AllMod.db
NOPURC_MODS=NoPurc.txt
TMPLIST=tmp.txt
MODNAMES=modnames.txt
PURC_MODS=Purc.txt


# CREATE THE LIST OF ALL MODULES ONLY

cut -f1 -d: $ALLMOD_LIST > $MODNAMES

# CREATE THE LIST OF MODULES NOT PURCHASED BY THE CUSTOMERS

cp $ALLMOD_LIST $TMPLIST ####What does this line do or mean####

for MOD_PURCHASED in `cat $1.db`
do
sed "/$MOD_PURCHASED/d" $TMPLIST > $NOPURC_MODS
cp $NOPURC_MODS $TMPLIST

done

cp $TMPLIST $NOPURC_MODS
cp $INP_FILE $TMPLIST
for MODULE in `cat $NOPURC_MODS | cut -d: -f1`
do
if [ "$MODULE" = "SHEAR_NEST" ]
then
ShearModuleNotPurchased="TRUE"
fi
if [ "$MODULE" = "OPTI_RECT" ]
then
OptirectModuleNotPurchased="TRUE"
fi
if [ "$ShearModuleNotPurchased" = "TRUE" ] && [ "$OptirectModuleNotPurchased" = "TRUE" ]
then

sed "/^# Begin Group \"Core Rect Sources\"/,/^# End Group/d;/^# Begin Group \"Core Rect Headers\"/,/^# End Group/d" $TMPLIST > $OUT_FILE

cp $OUT_FILE $TMPLIST

rm -rf ../../af/rectcore
rm -rf ../../include/advanced/rectcore
fi
 
Old 03-18-2008, 07:30 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966
this is not urgent for our voluntary members, and your choice of title gives no insight at all in to the issues you are after help about.if you want help, you need to respect those who kindly donate their time to help others.
 
Old 03-18-2008, 07:48 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Welcome to LQ!

Please note that "Urgent" does not make us move faster---some people will not even open the thread with such a title.

You have several constructs in here:
variable substitution (eg $ALLMOD)
sed addressing (eg sed "/address1/,/address2/d"---deletes everything from address 1 to 2)
redirection (>)
escaping to force literal interpretation (eg \"Core Rect Sources")

To decipher a particular expression, look for the basic construct, and then take it apart. I'll do one example:
sed "/^# Begin Group \"Core Rect Sources\"/,/^# End Group/d;/^# Begin Group \"Core Rect Headers\"/,/^# End Group/d" $TMPLIST > $OUT_FILE

This has the basic form:
sed "/addr1/,/addr2/d" $var1 > $var2 (there are two instances of the (address range/d) construct, separated by the semicolon.)
The above decodes to:
read from the location stored in var1
In the range of addr1 to addr2, delete all lines
write to the location stored in var2

Now decode the first address:
/^# Begin Group \"Core Rect Sources\"/
At the beginning of the line (^), find this phrase: # Begin Group "Core Rect Sources"
The escaped quotes are required to force them to be interpreted correctly in this context. (Read more on quoting in a good BASH manual)

For a good SED tutorial:http://www.grymoire.com/Unix/Sed.html
BASH manual:http://tldp.org/LDP/abs/html/
 
Old 03-19-2008, 12:59 AM   #4
joyds219
LQ Newbie
 
Registered: Mar 2008
Posts: 9

Original Poster
Rep: Reputation: 0
Thank you Very much pixellany . I am greatful for your help.as for the "urgent" part, i am sorry for that . it was mentioned so as to add a key word urgent for faster reply. any ways I shall not repeat that mistake again.
Thank you once again pixellany.
 
Old 03-19-2008, 03:47 AM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,985
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
And I took the liberty to rename the thread to something
more sensible ;}


Cheers,
Tink
 
Old 03-19-2008, 07:54 PM   #6
1337_penguin
Member
 
Registered: Jul 2005
Location: Brighton, UK
Distribution: Mainly Debian and Mepis, but also Slackware, Arch and Mandriva
Posts: 73

Rep: Reputation: 15
Hi,

I noticed that the 2 paths which you are assigning to the variables $INP_FILE and $OUT_FILE appear to be Windows paths. Where are the files actually located from the *n?x machine's point of view? (For instance, if it's a Samba share on a Windows machine, you'll need to mount it somewhere and then replace "E:" with the mount point.)

Also, the other variables ($ALLMOD_LIST, $NOPURC_MODS, $TMPLIST, $MODNAMES, and $PURC_MODS) will only work if they reside in the same directory as the script. Likewise, with the rm commands at the end, if you're unsure where the script will be executed from, it would be better to explicitly state the paths so as to avoid any unintended consequences.

1337_penguin
 
Old 03-19-2008, 08:21 PM   #7
prad77
Member
 
Registered: Mar 2008
Posts: 101

Rep: Reputation: 15
cp $ALLMOD_LIST $TMPLIST
It jus copies allmod_list to a tmp file.

sed "/$MOD_PURCHASED/d" $TMPLIST > $NOPURC_MODS
cp $NOPURC_MODS $TMPLIST


Deletes the $MOD_PURCHASED in $TMPLIST.
And redirects it to $NOPURC_MODS. Then it is copied as $TMPLIST.

Fedora Development

Last edited by prad77; 04-17-2008 at 03:15 AM.
 
  


Reply

Tags
cat, sed, shell scripting


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
Can someone explain how this script works? Sanborn Programming 18 06-15-2007 08:53 AM
Can Anyone Explain This? Tuzinor Linux - Hardware 8 10-27-2004 10:47 PM
Can somebody explain this to me? SyBEX Linux - Software 3 10-24-2004 05:32 PM
explain this little script plz nukeu666 Linux - Newbie 4 08-18-2004 12:52 AM
please someone, do explain this to me... Tisch Slackware 4 01-17-2004 10:37 AM


All times are GMT -5. The time now is 07:15 AM.

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 Google+: linuxquestions
Open Source Consulting | Domain Registration