sed -n option


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed -n option
# 1  
Old 07-12-2013
sed -n option

Hi i am facing problem with sed -n option could you please help me on this, i have a file test the contents of the file is

width="75">10/0 4/12</td>^M><a href='courtorders/100412zr.pdf' target="_blank">Miscellaneous Order</a></td>^M width="75">10/01/12</td>^M><a href='courtorde rs/100112zor.pdf' target="_blank">Order List</a></td>^M width="75"></td>^M><a href='' target="_blank"></a></td>

the above content is present in one line, so i have written code to separate

Code:
cat two | sed -e 's/<\/a><\/td>/\
/g'  -e 's/^M//g' -n -e '/pdf/p'

output of the above command is
Code:
 width="75">10/0 4/12</td>^M><a href='courtorders/100412zr.pdf' target="_blank">Miscellaneous Order
^M width="75">10/01/12</td>^M><a href='courtorde rs/100112zor.pdf' target="_blank">Order List
^M width="75"></td>^M><a href='' target="_blank">

according to last part of sed command it should print only the lines which have word "pdf" in it , but its not happening its printing lines which doesnt have "pdf" also so please help me to understand what i was doing wrong
# 2  
Old 07-12-2013
try this

Code:
 
cat two | sed -e 's/<\/a><\/td>/\
/g'  -e 's/^M//g' | sed -n '/pdf/p'

# 3  
Old 07-12-2013
I guess you can't use selective printing when combining multiple sed commands. Instead you could just pipe it to a new sed instance:

Code:
cat two | sed -e 's/<\/a><\/td>/\
/g'  -e 's/^M//g' | sed -n '/pdf/p'


Last edited by Subbeh; 07-12-2013 at 10:14 AM.. Reason: Nvm, millan beat me to it :)
This User Gave Thanks to Subbeh For This Post:
# 4  
Old 07-12-2013
Why not
Code:
sed -n '/pdf/ {s/^M//g; ...etc...;p}' two

?
# 5  
Old 07-12-2013
Yes if i use separate sed its working , but what is the problem if i use with -e option
# 6  
Old 07-13-2013
Code:
$ echo 'width="75">10/0 4/12</td>^M><a href='courtorders/100412zr.pdf' target="_blank">Miscellaneous Order</a></td>^M width="75">10/01/12</td>^M><a href='courtorde rs/100112zor.pdf' target="_blank">Order List</a></td>^M width="75"></td>^M><a href='' target="_blank"></a></td>' | awk -F "['/ ]" '{for(i=1;i<=NF;i++){if($i~/pdf/)print $i}}'
100412zr.pdf
100112zor.pdf

# 7  
Old 07-15-2013
Thanks all for your replies, but can any confirm that we cannot use multiple sed that is with -e option for selective text printing
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed one Liner option -e

Hi, I have the following command.(Delete all trailing blank lines at the end of a file.) sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' I don't understand the logic of this command and also I don't understand why -e is used. Can you please let me know the logic of this command and why three -e... (5 Replies)
Discussion started by: TomG
5 Replies

2. Shell Programming and Scripting

sed with -e option

sed "s/^/8,A1,$dat,id2_3,/g" -e sed "s/$/,,,,,,,,,,,/g" temporary wn m running this script m getting a error... plz help me with this.... O/p sed: -e expression #1, char 3: unterminated `s' command ---------- Post updated at 11:35 AM ---------- Previous update was at 11:33 AM... (7 Replies)
Discussion started by: nikhil jain
7 Replies

3. UNIX for Dummies Questions & Answers

emulating cat in sed with q option

Hi, I am aware that the below are the equivalent in sed for cat command. sed ':' sed -n 'p' Is there any way to emulate the same using "q" option in sed? Thanks (8 Replies)
Discussion started by: pandeesh
8 Replies

4. Shell Programming and Scripting

sed 'b' option

Hi, What does the following command do on files? sed '1b; $d' To me it just deletes the last line of the file. If so what is the significance of sed's 'b' option? Thanks (1 Reply)
Discussion started by: royalibrahim
1 Replies

5. UNIX for Dummies Questions & Answers

sed -i option example

Can anyone give detailed and example for sed -i option. Where can we use this option?:) (3 Replies)
Discussion started by: gwgreen1
3 Replies

6. Shell Programming and Scripting

sed delete option

I have tried doing this to delete some lines: sed '1,10d' file Now I want to specify a variable as a line number for example: lastline=wc -l file linestart=$lastline - 20 sed '$linestart,$lastlined' file but this will give error: sed: -e expression #1, char 3: extra characters after... (4 Replies)
Discussion started by: zorrox
4 Replies

7. Shell Programming and Scripting

Help needed sed: illegal option -- i

hello. i have a script, but in solaris i get this message sed: illegal option -- i whats wrong? With Ubuntu there is no problem. Thanks for help. #!/bin/bash for file in $(find /directory..../Test/*.txt -type f) do head -n 1 $file | egrep '^#!' if then sed -i '2i\Headertext'... (3 Replies)
Discussion started by: fertchen
3 Replies

8. Shell Programming and Scripting

sed insert option(-i) in shell script

Hi, Please tell me how to use insert option of sed in a shell script on Solaris/AIX plateform. For example I need to insert few lines on top of every file whose name starts with say "SOL_DEL". Thanx. (2 Replies)
Discussion started by: sanjay1979
2 Replies

9. Shell Programming and Scripting

Env Variable substituion in Sed (-s option)

Folks, I've been trying to use the ENV variable with slashes(/) in its value inside the sed substitution.. Sed 's/myval/'$MYVAL'/' file1 >> file.tmp If MYVAL=<sometext>, it works. if MYVAL=/home/venkat, it doesnt. *************************** bash-2.05$ export VAL=/home/venkat... (5 Replies)
Discussion started by: gvsreddy_539
5 Replies

10. UNIX for Dummies Questions & Answers

sed option to delete two words within a file

Could someone please help me with the following. I'm trying to figure out how to delete two words within a specific file using sed. The two words are directory and named. I have tried the following: sed '//d' sedfile sed '//d' sedfile both of these options do not work..... ... (4 Replies)
Discussion started by: klannon
4 Replies
Login or Register to Ask a Question