Sponsored Content
Top Forums Shell Programming and Scripting RE or Sed to manipulate a document Post 302262808 by phpfreak on Saturday 29th of November 2008 02:25:45 AM
Old 11-29-2008
Thanks Ken but I think I oversimplified my example which is why this might not work. Totally not your fault but also, I think you missed that I wanted to throw those characters into a variable and use sed again to append it to my command like so...
Quote:
mycommand > bcfn.htmlbcfn
mycommand > cdcsfn.htmlcdcsfn
mycommand > dechfn.1.htmldechfn
mycommand > efchfsn.htmlefchfsn
mycommand > fpchn.6.htmlfpchn

mycommand bcfn > bcfn.html ;
mycommand cdcsfn > cdcsfn.html ;
mycommand dechfn > dechfn.1.html ;
mycommand efchfsn > efchfsn.html ;
mycommand fpchn > fpchn.6.html ;
Eventually I want to convert it into a script #!/bin/sh and this is why additionally, I wanted to terminate each line (not sure if it's even necessary though). I have two of my own scripts that I made waaaay long ago that'll get the same job done...

Code:
#!/bin/sh
#Search and replace using sed. 
#Output live with cat.
echo "Syntax is as follows:
# file arg1 arg2"
read FILE RPL1 RPL2
cat $FILE | sed s/$RPL1/$RPL2/ ;
#!/bin/sh
#Search and replace using sed. 
#No output
echo "Syntax is as follows: 
# file arg1 arg2"
read FILE RPL1 RPL2
touch tmp.Ps23zp2s.2-Fpps3-wmmm0dss3
cat $FILE | sed s/$RPL1/$RPL2/ > tmp.Ps23zp2s.2-Fpps3-wmmm0dss3 ;
mv tmp.Ps23zp2s.2-Fpps3-wmmm0dss3 $FILE
echo "task completed"
#


-except.. I need to somehow have the characters thrown into a variable somehow to use sed again to append it as part of the command. I think the best way to do this is to have a sed sequence that works to do this then loop it through the file. Heck with that, given that a smaller test batch works, I can throw my command into the loop to get it all done under one script instead of two.

I'm still learning but what I think is relevant for all to know is that the characters after .html will be alphanumeric ([a-zA-Z0-9_] or \w) as I understand.


-----------------------------------------

What the heck.. here is the below so that all may follow what I'm trying to do...


Code:
--cut for brevity
man2web > apmd.8.htmlapmd
man2web > apropos.1.htmlapropos
man2web > apxs.8.htmlapxs
man2web > ar.1.htmlar
man2web > arch.1.htmlarch
man2web > arp.8.htmlarp
man2web > as.1.htmlas
man2web > ascii-xfr.1.htmlascii-xfr
man2web > ascii.7.htmlascii
man2web > asciitopgm.1.htmlasciitopgm
man2web > asctime.3.htmlasctime
man2web > ash.1.htmlash
man2web > asin.3.htmlasin
man2web > asinh.3.htmlasinh
man2web > assert.3.htmlassert
--cut for brevity


Last edited by phpfreak; 11-29-2008 at 04:36 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Manipulate files

Hi everybody: I have a problem. I have a output files which have this pattern: number1 --space block1a - 7rows/10columns/65elements --space block1b - 7rows/10columns/65elements --space block1c - 7rows/10columns/65elements --space number2 --space block2a - 7rows/10columns/65elements... (0 Replies)
Discussion started by: tonet
0 Replies

2. Shell Programming and Scripting

sed or other tool to manipulate data, including email addresses

I have a list of names and email addresses, like this. The <tab> markers are actually tabs. joe.blow <tab> joe.blow@wherever.com tom.t.hall <tab> tom.t.hall@wherever.com john.r.smith <tab> john.r.smith@wherever.com sally.jones <tab> sally.jones@state.or.us I want to parse the data so that... (3 Replies)
Discussion started by: manouche
3 Replies

3. UNIX for Dummies Questions & Answers

using sed to manipulate text in files

Hi, I have a slight problem in trying to manipulate the text within a file using the "sed" command in that the text i need changed has "/" slashes in. I have a .sh script that scans the "/db/sybbackup/" directories for any .dmp file older than 2 days and then to >> the information to a file called... (3 Replies)
Discussion started by: Jefferson333
3 Replies

4. Shell Programming and Scripting

Sed command to find, manipulate and replace a number

Hi, Im very new to the world of sed so I'm really not even sure if this is possible. What i need to do is read from a flat file and every time i see this line: VAL=123,456 I need to change 456 to 457 for every occurence of this line in the file. The numbers 123 and 456 are different for... (6 Replies)
Discussion started by: LT_2008
6 Replies

5. Shell Programming and Scripting

manipulate postscript via sed

dear all, on solaris10 for x86 i am trying to modify the creation date of a postscript file with sed in a csh script. sed is driving me crazy though...i think due to the spaces in the string i am trying to substitute?? part of the postscript file: %!PS-Adobe-3.0... (3 Replies)
Discussion started by: lada niva
3 Replies

6. Shell Programming and Scripting

Manipulate lines with sed/awk

Hey All, I need to reorganize a file's text. Here is the source: host John_Doe filename "config.cfg"; hardware ethernet 98:10:3d:13:8f:98; fixed-address 10.10.10.29; } host Jane_Doe filename "config.cfg"; hardware ethernet 98:13:11:fd:5a:57; fixed-address 10.10.5.24; } host... (2 Replies)
Discussion started by: TheBigAmbulance
2 Replies

7. Shell Programming and Scripting

sed script to manipulate the /etc/passwd file

Hi. Can anybody help me with a script to extract usernames, shell and home_directory from the /etc/passwd file. I am stuck (2 Replies)
Discussion started by: Pauline mugisha
2 Replies

8. Shell Programming and Scripting

Here document inside a here document?

Can we use a here document inside a here document? Something like this ssh user@remotehost << REMOTE sudo vserver vsernamename enter << VSERVER perform actions on vserver. VSERVER REMOTE (6 Replies)
Discussion started by: mnanavati
6 Replies

9. Shell Programming and Scripting

Manipulate columns using sed

Hello, I would like to remove the first column of lines beginning by a character (in my case is an open square bracket) and finishing by a space (or any other delimiter). For example: string1 string2 string3 to string2 string3 I found this previous topic: ... (1 Reply)
Discussion started by: stoyanova
1 Replies

10. Shell Programming and Scripting

Manipulate "&" in sed

Is it possible to manipulate the ampersand in sed? I want to sum +1 to all numbers in a file. Example that doesn't work:sed "s/\{1,2\}/$(expr & + 1)/g" filenameAlso, how to return 02 instead of 2 from expr? (8 Replies)
Discussion started by: teresaejunior
8 Replies
XMLSTARLET(1)							 xmlstarlet Manual						     XMLSTARLET(1)

NAME
xmlstarlet - command line XML/XSLT toolkit SYNOPSIS
xmlstarlet [<options>] [<command>] [<cmd-options>] INTRODUCTION
XMLStarlet is a set of command line utilities (tools) which can be used to transform, query, validate, and edit XML documents and files us- ing simple set of shell commands in similar way it is done for plain text files using UNIX grep, sed, awk, diff, patch, join, etc commands. This set of command line utilities can be used by those who deal with many XML documents on UNIX shell command prompt as well as for auto- mated XML processing with shell scripts. OPTIONS
--version Display the version of xmlstarlet. --help Display help. COMMANDS
Type: xmlstarlet <command> --help <ENTER> for command help Available commands include: ed (or edit) Edit/update XML document(s). sel (or select) Select data or query XML document(s) (XPATH, etc). tr (or transform) Transform XML documents(s) using XSLT. val (or validate) Validate XML document(s) (well-formed/DTD/XSD/RelaxNG). fo (or format) Format XML document(s). el (or elements) Display element structure of XML document. c14n (or canonic) XML canonicalization. ls (or list) List directory as XML. esc (or escape) Escape special XML characters. unesc (or unescape) Unescape special XML characters. pyx (or xmln) Convert XML into PYX format (based on ESIS - ISO 8879). p2x (or depyx) Convert PYX into XML. REFERENCES
XMLStarlet is a command line toolkit to query/edit/check/transform XML documents (for more information see http://xmlstar.source- forge.net/). AUTHOR
Mikhail Grushinskiy. XMLSTARLET(1)
All times are GMT -4. The time now is 05:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy