![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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
|
|||
|
|||
|
Quote:
|
|
#4
|
|||
|
|||
|
Yes it is not replacing. It doing some other thing
|
|
#5
|
||||
|
||||
|
You are right, ghostdog74 -- my eyes didn't catch this one.
|
|
#6
|
|||
|
|||
|
Quote:
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:
Quote:
Thanks Nagarajan Ganesan |
|
#7
|
||||
|
||||
|
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' |
||||
| Google The UNIX and Linux Forums |