copy and paste a specific line

Hi
I am having some trouble cut and paste a file based on the content of another file.

I have a file called draft. I need to cut and paste its content to another file based on the content of a file called proc.txt

The content of proc.txt is like the following:
/vobs/aw/database/a.proc@@/main/2

I have written the following code:

#!/bin/sh
while read line
do
   grep "$line" ./draft >> ./output.txt
   sed -n "/$line/d" ./draft
done < ./proc.txt

The output.txt shows the correct result. However, I am not able to remove "$line" from the draft file.

I keeps getting the following error message
"sed: -e expression #1, char 82: expected newer version of sed"

Does anyone know what's wrong with my sed command?

Any input will be really appreciated

Thanks

Hi,

I think there is a fault in ur sed command. Plz tell me what is ur actula file content and what do u want finally as output?

mohan

Hi
In my draft:
author:
date:
/vobs/aw/database2/a.proc@@/main/2
/vobs/aw/database3/b.proc@@/main/2
/vobs/aw/database5/c.proc@@/main/2

In my proc.txt
/vobs/aw/database3/b.proc@@/main/2

The output.txt that I am hoping to get:
author:
date:
/vobs/aw/database2/a.proc@@/main/2

/vobs/aw/database5/c.proc@@/main/2

mohan, can you give me some assistant?

Thanks

Upgrade Sed! your code works fine on lateset sed (4.1.5)

Hi,

#!/bin/sh
while read line
do
   grep "$line" ./draft >> ./output.txt
   sed -n "/$line/d" ./draft
done < ./proc.txt

After executing the above code using set -x, the sed command will look like

+sed -n //vobs/aw/database3/b.proc@@/main/2/d

which is an incorrect sed command.

Your sed should be like

 sed /\/vobs\/aw\/database3\/b.proc@@\/main\/2/d draft

to execute successfully.

Regards,
Chella

Sorry, I probably didn't make my question clear.

I have a file (proc.txt) which has a list of lines I want to remove from a file (draft). I can not hard code the lines in my shell script since each line in the proc.txt are different.
I believe I need a loop to check each line in proc.txt and remove the line from (draft) and copy them to a file.
So the input/output I am hoping to get is

Draft(before remove)
Author:
Date:
1 /vobs/aw/database/a.proc/
2 /vobs/aw/database2/b.proc/
3 /vobs/aw/database4/a.proc/
4 /vobs/aw/database4/b.proc/
5 /vobs/aw/database2/d.proc/
...etc

proc.txt
/vobs/aw/database2/b.proc/
/vobs/aw/database4/b.proc/
...etc

I hope to write a script to achieve the following:
draft(after remove)
Author:
Date:
1 /vobs/aw/database/a.proc/

3 /vobs/aw/database4/a.proc/

5 /vobs/aw/database2/d.proc/
...etc

proc.txt(no change)
/vobs/aw/database2/b.proc/
/vobs/aw/database4/b.proc/
...etc

output.txt(new file)
2 /vobs/aw/database2/b.proc/
4 /vobs/aw/database4/b.proc/

I hope I have made my question more clear.
Is it possible to use shell script to achieve this?

Thanks in advance for your help

Hi All
I have spent almost a week trying to resolve my cut issue.

I have two files:
new:
79 /vobs/aw/database/proc/awAcctMgmt/awGetOptionCallActionByLevel.proc@@/main/solmar08/1

80 /vobs/aw/database/proc/awAcctMgmt/awGetOptionOrderActionByLevel.proc@@/main/solmar08/1

proc.txt
/vobs/aw/database/proc/awAcctMgmt/awGetOptionCallActionByLevel.proc@@/main/solmar08/1

I try to remove lines in (new) based on (proc.txt)

The following code works on cygwin but it doesn't work on SunOS 5.8

#!/bin/bash



DRAFT="./new"

REMOVE="./proc.txt"

TMP="/tmp/proc.tmp"



cat $REMOVE | while read line; do

    awk -v rem="${line}" '{if ($2 != rem) {print $0} else {print ""}}' ${DRAFT} > ${TMP}

    mv ${TMP} ${DRAFT}

done

I get the following error message
awk: syntax error near line 1
awk: bailing out near line 1

I also try sed instead of awk

sed '/'"${line}"'/d' ${DRAFT}

I get the following error message
First RE may not be null

I am really stucked. :frowning:
Could someone please give me some assistant...

On Solaris, try using "nawk" instead of "awk".