The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-17-2007
lijju.mathew lijju.mathew is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 10
Sed Help !

Hi,

I have a command in one of my shell script as below.

sed -n "/^$a/,\$p" $home/abc.log

$a and $home are variables. Not sure about $p.

Can you please let me know what this command is exactly trying to do.

Thanks in advance
LM
  #2 (permalink)  
Old 04-17-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Lijju,
The "sed" command: sed -n "/^$a/,\$p" $home/abc.log
Will replace all records in the file "$home/abc.log" that start with the value of the
variable "$a" by a three character string ",$p" (comma-dollar-p).
Because there is a backslash "\", the dollar sign "$" is treated literally, as opposed
to a prefix of a shell variable.
  #3 (permalink)  
Old 04-17-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,536
Quote:
Originally Posted by Shell_Life
Lijju,
The "sed" command: sed -n "/^$a/,\$p" $home/abc.log
Will replace all records in the file "$home/abc.log" that start with the value of the
variable "$a" by a three character string ",$p" (comma-dollar-p).
Because there is a backslash "\", the dollar sign "$" is treated literally, as opposed
to a prefix of a shell variable.
don't think it does replacement. there should be 's' modifier for replacement.
  #4 (permalink)  
Old 04-17-2007
lijju.mathew lijju.mathew is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 10
Yes it is not replacing. It doing some other thing
  #5 (permalink)  
Old 04-17-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
You are right, ghostdog74 -- my eyes didn't catch this one.
  #6 (permalink)  
Old 04-17-2007
ennstate ennstate is offline
Registered User
  
 

Join Date: Mar 2007
Location: Chennai
Posts: 222
Quote:
Originally Posted by Shell_Life
Lijju,
The "sed" command: sed -n "/^$a/,\$p" $home/abc.log
Will replace all records in the file "$home/abc.log" that start with the value of the
variable "$a" by a three character string ",$p" (comma-dollar-p).
Because there is a backslash "\", the dollar sign "$" is treated literally, as opposed
to a prefix of a shell variable.
Shell_life,
I dont think so. It will print all lines of the file between the line in the file that begins with the value of $a and the "$" - Last line of the file.

Simply once the sed finds out the line which begins with the value of $a,it prints all lines from there to the end of the file.

Example:
Assuming the variable "a" is set to "the" ie a=the
Quote:
1) cat abc.log
The beauty
he is the
no the
the fdsf
The big boss

HTML Code:
sed -n "/^$a/,\$p" abc.log
OUTPUT:
the fdsf
The big boss
Quote:
2)cat abc1.log
the first linme
no matched line
good
here is the end of the file

Code:
sed -n "/^$a/,\$p" abc1.log
OUTPUT:
the first linme
no matched line
good
here is the end of the file
Please correct me of am wrong.

Thanks
Nagarajan Ganesan
  #7 (permalink)  
Old 04-17-2007
reborg's Avatar
reborg reborg is online now Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,211
ennstate, you are correct.

The $ is escaped because of the use of double quotes. The shell would otherwise attempt to perform substitution.

assuming a=foo

Without variables, one would normall write this as:

Code:
sed '/^foo/,$p'
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:43 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0