using sed to manipulate text in files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers using sed to manipulate text in files
# 1  
Old 08-08-2008
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 "removeold.txt". Essencially the text in the file is shown in below in blue.
/db/sybbackup/databases/ENT_IO_20080101.dmp
I have tried the following using the sed command
1. sed 's/{/db/sybbackup}/{rm /db/sybbackup}/' removeold.txt >> rmscript.sh
2. PATH="/db/sybbackup/"
REPPATH="rm /db/sybbackup"
sed 's/${PATH}/${REPPATH}/' removeold.txt >> rmscript.sh
I am hoping to get the following end result using "sed" and not to use "nawk". mind you, i have only been working on Solaris now for a week and am still waiting for my training Smilie
rm /db/sybbackup/databases/ENT_IO_20080101.dmp
Can anyone please point me in the right direction to get past the "/" problem in "sed"
# 2  
Old 08-08-2008
Ok, sorted it out, I just replaced the "/" with a "!"

sed 's/{/db/sybbackup/}{rm /db/sybbackup}/' removeold.txt >> rmscript
sed 's!/db/sybbackup!rm /db/sybbackup!' removeold.txt >> rmscript

Suppose i just needed to talk myself thru this :-)
# 3  
Old 08-08-2008
Hi.
Quote:
Originally Posted by Jefferson333
Suppose i just needed to talk myself thru this :-)
Yes, that often works. Some alternatives:
Quote:
So when you're really stuck, when you've looked at the problem in every way you can, when every tool in your toolbox has failed you, take time off to think. Go ride a bike. Take the afternoon off and come back in the evening to give yourself a new perspective. Explain the problem to a friend, a manager, a dog, or the wall. The external challenge to your assumptions is often the catalyst that breaks the barrier down.

-- excerpt from Embedded.com - The ten secrets of embedded debugging
I like the one about the dog. Thanks for posting the solution -- it may help someone else ... cheers, drl
# 4  
Old 08-09-2008
Quote:
I like the one about the dog. Thanks for posting the solution -- it may help someone else ... cheers, drl
Smilie Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to manipulate a text file and store each version for every changes in a directory?

I attached both picturehttps://1drv.ms/t/s!Aoomvi55MLAQh1jODfUxa-xurns_ and *.txt file of a sample work file. In this file Reactions which only start with "r1f", "r2f", "r3f"......and so on. And for each reaction the reaction rates is situated couple of lines later with a "+" sign. For each... (1 Reply)
Discussion started by: Atta
1 Replies

2. Shell Programming and Scripting

A better way to manipulate text

Good morning everyone, I'm currently trying to convert an environment variable into a string and then attach it at the end of a command and launch it. I have the following right now, but it's very ugly: AMI_TAGS="env=test,country=XX,city=blah,galaxy=blahblah" aws ec2 create-tags... (8 Replies)
Discussion started by: da1
8 Replies

3. UNIX for Beginners Questions & Answers

How can I remove partial duplicates and manipulate text?

Hello, How can I remove partial duplicates and manipulate text in bash using either awk, grep or sed? Thanks. Input: ted,"foo,bar,zoo" john-son,"foot,ben,zoo" bob,"bar,foot" Expected Output: foo,ted bar,ted zoo,ted foot,john-son ben,john-son (4 Replies)
Discussion started by: tara123
4 Replies

4. Shell Programming and Scripting

Manipulate the text file in UNIX

Hi All, I have a file like below and i have 2 questions on this (They are 3 lines starts with 01 , 02 and 03. but is 01abc333644554 234 2334535 34534535355353 sfsdf345455 353 4543 jgkg tty 7676 02cdesdfsdfsdf 234 wesdfsdf 345345 234234 234234 2342342 dfgdfg sdfgg dgdgdg fgvfs... (6 Replies)
Discussion started by: siva.pitchai
6 Replies

5. 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

6. 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

7. 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

8. 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

9. Shell Programming and Scripting

RE or Sed to manipulate a document

I have a file with a list of about 2500 lines that I'd like to reformat using some regex in notepad++ or sed from my box (FreeBSD 6.3-RELEASE i386) to do the following: convert from: mycommand > mydocument0.htmlbcfn mycommand > mydocument1.htmlcdcsfn mycommand > mydocument2.htmldechfn... (6 Replies)
Discussion started by: phpfreak
6 Replies

10. Shell Programming and Scripting

Script to manipulate logfile text

Hi guys, I was wandering if a Shell guru could give me some advice on tackling a problem. I have used a mixture of grep, cut and awk to get data from a log file in the following format: 14/11/08 10:39: Checking currenly : Enabled 14/11/08 10:39: Records allocated : 221... (11 Replies)
Discussion started by: rosspaddock
11 Replies
Login or Register to Ask a Question