Problem with sed
The thing is that the command for sed resembles the following
Code:
sed 'address action' file_name How shall I do that???? |
Example:
You want the address to be the result of running "ls|grep -o cat" SED command to print the line containing that result: Code:
sed -n "/$(ls|grep -o cat)/p" file_name |
Have a look at the output produced by
Code:
$sed -n "/$(ls|grep a)/p" abc1 Suppose that I have a variable which contains the required line number in a file. Now how can I use this variable as the address for sed command???????? |
What does "ls|grep a" produce?
On my system (home folder) it produces 6 filenames, some with periods before the extensiong, and all separated by newlines. Pretty much guaranteed to make the SED addressing go berserk. In the form I showed, you have to filter the output of the command to get something that is rational to use as an address. |
Quote:
eg: sed -n '1p' filename #prints line 1 sed -n '1,5' filename #prints lines 1-5 sed -n '1,/keyword/' #prints line thru the line containing "keyword" Go here for a really good SED tutorial: http://www.grymoire.com/Unix/ |
Well let me describe the problem->
Consider the file: Code:
$ cat student.txt So can You help me out.... Just as a matter of interest can you tell me some other ways... |
you can just use the shell..no need to call external command
Code:
read -p "Enter number: " number Code:
# ./shell.sh Code:
awk 'BEGIN{ |
lemon*;
Did you read the tutorial I suggested? Code:
read -p "enter roll number to delete: " num |
Just a little note: I'd add a colon in the address, to avoid that (for example) 18 deletes all the lines having 180, 181, 182, 183...
Code:
sed "/^$num:/d" filename > newfilename |
All times are GMT -5. The time now is 10:55 AM. |