How to copy text with ed to new file ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to copy text with ed to new file ?
# 1  
Old 11-07-2010
How to copy text with ed to new file ?

Alright, so in ed i do a subsititution:

Code:
ed file << 'HERE'
s/.*h2.*>\(.*\)<.*/\1/p
HERE

This gives me my desired line:

Code:
Errors found while checking this document as XHTML 1.0 Transitional!

But how would i put this line in a temporary file ?
# 2  
Old 11-07-2010
w file
# 3  
Old 11-07-2010
Code:
ed file << HERE > /dev/null 2>&1
, g/<h2>/
s/.*h2.*>\(.*\)<.*/\1/
. w newfile
HERE

Code:
$ cat newfile
Errors found while checking this document as XHTML 1.0 Transitional!

# 4  
Old 11-07-2010
It's been so long, does ed search for the right line with just an s, no address?
# 5  
Old 11-07-2010
Good question... it's been so long Smilie

ed on OS X was acting differently to on Linux. I don't know which was correct, so I used g to address the lines, which seemed to agree with both.

Code:
$ cat file1
Some blah
<h2>Errors found while checking this document as XHTML 1.0 Transitional!</h2>
some more blah
<h2>Errors found while checking this document as XHTML 1.0 Transitional!</h2>
even more blah

OS X:
Code:
ed file1 << HERE
1,$ g/<h2>/
s/.*h2.*>\(.*\)<.*/\1/
. w file2
HERE

Output:
Code:
Errors found while checking this document as XHTML 1.0 Transitional!

Code:
ed file1 << HERE
g/<h2>/
1,$ s/.*h2.*>\(.*\)<.*/\1/
. w file2
HERE

Output:
Code:
Errors found while checking this document as XHTML 1.0 Transitional!


CentOS
Code:
ed file1 << HERE
1,$ g/<h2>/
s/.*h2.*>\(.*\)<.*/\1/
. w file2
HERE

Output:
Code:
Errors found while checking this document as XHTML 1.0 Transitional!


Code:
ed file1 << HERE
g/<h2>/
1,$ s/.*h2.*>\(.*\)<.*/\1/
. w file2
HERE

Output:
Code:
even more blah

I thought that this should be enough:
Code:
ed file1 << HERE
1,$ s/.*h2.*>\(.*\)<.*/\1/
. w file2
HERE

which on OS X was correct, but on CentOs was giving the "even more blah" output.

ex seems to work the same on both without g:
Code:
ex file1 << HERE
1,$ s/.*h2.*>\(.*\)<.*/\1/
. w file2
HERE

Output:
Code:
Errors found while checking this document as XHTML 1.0 Transitional!

This User Gave Thanks to Scott For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy text from web page and add to file

I need help to make a script for Ubuntu to OSCam that copy the text on this website that only contains "C: ip port randomUSERNAME password" and want to exclude the text "C:" and replace the rest with the old in my test.server file. (line 22) device = ip,port (line 23) user =... (6 Replies)
Discussion started by: baxarn
6 Replies

2. Shell Programming and Scripting

Copy text and create new file

I have a directory with ~500 files that look like below. I need to copy each unique entry up until the second_ only once and put a .txt in place of the _. I am not quite sure how but have the below as a startThank you :). cp -u file1.txt "$(cat output.txt)" file1.txt ... (4 Replies)
Discussion started by: cmccabe
4 Replies

3. UNIX for Dummies Questions & Answers

Hoe to copy selected strings from file into another text file

Hi Experts, I just want to copy some selected strings from a a file into a new .txt file . I am using below command to find the data now want to copy the search results into another .txt file please help me . find /Path -exec grep -w "filename1|filename1|filename1|" '{}' \;... (2 Replies)
Discussion started by: mumakhij
2 Replies

4. Shell Programming and Scripting

How to copy one file into another except some text

I have file input like- abc,"123",""123","123","123","123","123","123","123","123","123","123","123","123", abc,"123","123","123","123","123","123","123","123","123""123",abc etc Input file consists of 1000 records and i want to copy into final file except abc abc is at fixed position... (6 Replies)
Discussion started by: AhmedLakadkutta
6 Replies

5. Shell Programming and Scripting

Copy selective lines from text file

Hello, I have a text file which I need to check for presence of certain tags, and then copy a subsequent portion of text into another file. The tag matching canbe done with Grep but I do not know how to copy selective lines from one file to another. Is it possible do that? I checked up some... (8 Replies)
Discussion started by: ajayram
8 Replies

6. Homework & Coursework Questions

copy files inside a text file

Hi Guys , I am new to this and Hi to all ,Need your help I am trying to copy Files which are inside file.txt The files inside file.txt are inthe below order file1.log file2.log file3.log ....... I want to copy these files to an output Directory , Please help (1 Reply)
Discussion started by: hc17972
1 Replies

7. Homework & Coursework Questions

copy files inside a text file

Hi Guys , I am new to this and Hi to all ,Need your help I am trying to copy Files which are inside file.txt The files inside file.txt are inthe below order file1.log file2.log file3.log ....... I want to copy these files to an output Directory , Please help (1 Reply)
Discussion started by: hc17972
1 Replies

8. UNIX for Dummies Questions & Answers

Shell script to search for text in a file and copy file

Compete noob question.... I need a script to search through a directory and find files containing text string abcde1234 for example and then copy that file with that text string to another directory help please :eek: (9 Replies)
Discussion started by: imeadows
9 Replies

9. UNIX for Advanced & Expert Users

How to copy a string to a text file

I am using the following command to email a tex file as an attachment- cat mailtext.txt | elm -s "Subject" emailAddr where content of mailtext.txt is - "Body of email" This will attach foo.txt with the email. My problem is that the file foo.txt is ceated dynamically everytime with a... (5 Replies)
Discussion started by: hpuxlxboy
5 Replies

10. UNIX for Dummies Questions & Answers

I want to copy the text output from a 'nohup.out' file.

Hello, I have a nohup.out file that, when executed, outputs a spreadsheet file with four-to-seven columns of number. I want to copy this output (in its entirety), so that I could then paste it on excel@ , or Notepad@. Please help, thanks. (3 Replies)
Discussion started by: Iamthe great
3 Replies
Login or Register to Ask a Question