What's wrong with this sed command? delete & append


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting What's wrong with this sed command? delete & append
# 1  
Old 04-08-2008
What's wrong with this sed command? delete & append

I want to write a sed command that does the following work:

file:
Code:
<a>asdfasdf<\s>
     <line>hello</line>
       <b>adf<\c>
  <b>tttttttt<\c>

output:
Code:
name=hello

Code:
sed -e 's/^[ \t]*//' -n -e '/<line>/s/<[^<]*>//gp;' -e 's/^/name="/g' file

but I can not append "=" after getting the line with front space deleted.
I have an alternate way to get around the problem.

But I don't understand why it wouldn't work.
Any suggestions would be great!!!

Last edited by Yogesh Sawant; 04-08-2008 at 02:39 PM.. Reason: added code tags
# 2  
Old 04-08-2008
try something like this, I don't get some of your regexes:
Code:
 grep '<line>' filename | sed 's/\<[\/a-z]*\>//g'

# 3  
Old 04-08-2008
Try:

Code:
sed -n '/<line>/s/.*>\(.*\)<.*/name=\1/gp' file

Regards
# 4  
Old 04-08-2008
MySQL

Quote:
Originally Posted by Franklin52
Try:

Code:
sed -n '/<line>/s/.*>\(.*\)<.*/name=\1/gp' file

Regards
beautiful~SmilieSmilieSmilieSmilieSmilieSmilieSmilieSmilie
# 5  
Old 04-08-2008
put this in a sed script
cat >sedscript
Quote:
/<line>/{
s/<line>\(.*\)<\/line>/name=\1/g
p
}

# sed -n -f sedscript test
# 6  
Old 04-08-2008
you should use a dedicated XML/HTML parser instead
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to append word at end of line

hello Team, I am looking for sed command or script which will append word at end of line. for example. I want to validate particular filesystem with mount |<filesystem name> command. if nodev parameter is not there then it should add in the fstab file with receptive to the filesystem. # mount... (8 Replies)
Discussion started by: ghpradeep
8 Replies

2. Shell Programming and Scripting

SFTP Shell Script Get & Delete && Upload & Delete

Hi All, Do you have any sample script, - auto get file from SFTP remote server and delete file in remove server after downloaded. - only download specify filename - auto upload file from local to SFTP remote server and delete local folder file after uploaded - only upload specify filename ... (3 Replies)
Discussion started by: weesiong
3 Replies

3. Shell Programming and Scripting

If && command giving wrong output

Hi All, I am trying to run a script which will search for 2 strings(stopped,started) in a text file and echo an output depending on below condition -bash-3.2$ cat trial1.txt v ggg f -bash-3.2$ cat trial1.sh VAR9=` grep 'stopped' /tmp/trial1.txt` VAR10=` grep 'started'... (4 Replies)
Discussion started by: srkmish
4 Replies

4. Shell Programming and Scripting

How to append a value to the output after using sed command?

Hi All, I have a file where I am converting newlines to comma separated values but I would like to append zero if the output is empty Here is the command I am using sed -n -e 'H;${x;s/\n/,/g;s/^,//;p;}' test1.txt test1.txt will have comma seperated values but sometimes this file can be... (6 Replies)
Discussion started by: rajeevm
6 Replies

5. Shell Programming and Scripting

How to use variables in 'sed' append command?

HELLO!! I'm trying to pass a variable with in the 'sed' command (which would add some piece of code to file at a particular line). We can use sed '{line-number}a\ alfjaljf\ aslfjsfsjafl\ adlfjaf\' file.txt If file.txt is Now, I would like to add the parameter 'lmn' after... (1 Reply)
Discussion started by: mjavalkar
1 Replies

6. Red Hat

Need Script to ZIP/SAVE & then DELETE Log file & DELETE ZIPS older than 12 months

ENVIROMENT Linux: Fedora Core release 1 (Yarrow) iPlanet: iPlanet-WebServer-Enterprise/6.0SP1 Log Path: /usr/iplanet/servers/https-company/logs I have iPlanet log rotation enabled rotating files on a daily basis. The rotated logs are NOT compressed & are taking up too much space. I... (7 Replies)
Discussion started by: zachs
7 Replies

7. Shell Programming and Scripting

How to append something to a word using sed command

Hi, How to append something to already existing word. Suppose, I have the following line as a part of a file. VVV= jdbc:... (6 Replies)
Discussion started by: Dpu
6 Replies

8. Shell Programming and Scripting

SED to delete last word on line...what's wrong?

I have a line that gets pulled from a database that has a variable number of fields, fields can also be of a variable size. Each field has a variable number of spaces between them so there is no 'defined' delimiter. The LastData block is always a single word. What I want to do is delete the... (2 Replies)
Discussion started by: Bashingaway
2 Replies

9. UNIX for Dummies Questions & Answers

Sed: Append and Delete?

I think it should be obvious what I'm trying to do from my command, but just to be sure it's clear, I'm trying to append 2 lines after a matched line and then delete 2 other lines within a file. I'd like to do it in 1 line if possible. This code isn't working, but hopefully it's just a syntax... (0 Replies)
Discussion started by: earnstaf
0 Replies

10. Shell Programming and Scripting

SED: match pattern & delete matched lines

Hi all, I have the following data in a file x.csv: > ,this is some text here > ,,,,,,,,,,,,,,,,2006/11/16,0.23 > ,,,,,,,,,,,,,,,,2006/12/16,0.88 < ,,,,,,,,,,,,,,,,this shouldnt be deleted I need to use SED to match anything with a > in the line and delete that line, can someone help... (7 Replies)
Discussion started by: not4google
7 Replies
Login or Register to Ask a Question