copy and paste a specific line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting copy and paste a specific line
# 1  
Old 02-18-2008
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:
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
# 2  
Old 02-18-2008
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
# 3  
Old 02-18-2008
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
# 4  
Old 02-18-2008
Upgrade Sed! your code works fine on lateset sed (4.1.5)
# 5  
Old 02-18-2008
Quote:
Originally Posted by tiger99
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:
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,

Code:
#!/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
Code:
+sed -n //vobs/aw/database3/b.proc@@/main/2/d

which is an incorrect sed command.

Your sed should be like
Code:
 sed /\/vobs\/aw\/database3\/b.proc@@\/main\/2/d draft

to execute successfully.

Regards,
Chella
# 6  
Old 02-18-2008
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
# 7  
Old 02-24-2008
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

Code:
#!/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

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

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


I am really stucked. Smilie
Could someone please give me some assistant...
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep string in a file and paste next line in a specific way

Hello, I know there are many questions and replies regarding grep command. What I would like to do is a bit different. File A: hello world welcome to my page this is my test site how are you I am fine, thank you where have you been I was in hospital really hope you are fine now Thanks,... (10 Replies)
Discussion started by: baris35
10 Replies

2. UNIX for Dummies Questions & Answers

Copy/paste in vi editor

Hello guys, I am trying to copy a line in vi editor and paste it with below commands but paste command is not working and instead of paste action prints the p character!! I should also mention that the server is Solaris... 1) crontab -e 2) j to move down 3) yy to copy the line 4) o to... (4 Replies)
Discussion started by: Newman
4 Replies

3. Shell Programming and Scripting

Copy n paste n times

I have one mainframe copy book where I want to copy n times depend on occurs which mention below. Example: Below highlighted row mention “occurs 2 times” so I need to copy 2 times till next label 10. C14992 10 FILLER PIC X(2835). 01 ... (7 Replies)
Discussion started by: srivalli
7 Replies

4. Shell Programming and Scripting

Copy some line and paste it after some line in same file

Hi, I want to know how I can copy line 6th to 10th and paste it after 17th line in same file. Thanks, Biplab (19 Replies)
Discussion started by: Biplab
19 Replies

5. UNIX for Dummies Questions & Answers

vim copy line and paste at the beginning, middle, and end of another line

How would you do vim copy line and paste at the beginning, middle, and end of another line. I know yy copies the whole line and p pastes the whole line, but on its own separate line. Sometimes I would like to copy a line to the beginning, middle, or end of another line. I would think this would be... (3 Replies)
Discussion started by: cokedude
3 Replies

6. UNIX for Dummies Questions & Answers

vi copy/paste problem

I'm having a problem copy/pasting from a txt file in windows to vi. What happens is I copy a chunk of text, go to the putty terminal, go into insert mode, and right click, and it will stop pasting at a random point and freeze up. Nothing I do gets out of it. This only happens on my account... (1 Reply)
Discussion started by: solidarity
1 Replies

7. Shell Programming and Scripting

How to copy and paste line in shell script

Hi I want to grep for a line and copy and paste that line. for Example ---- file abc.txt ---- host=atlx1 sid=atld1 mail=abc@abc.com host=atlx2 sid=atld2 mail=xyz@abc.com host=atlx3 sid=atld3 mail=def@abc.com host=atlx4 sid=atld4 mail=mno@abc.com --- end of file abc.txt ---- Now I... (16 Replies)
Discussion started by: upsrk
16 Replies

8. UNIX for Dummies Questions & Answers

cut, copy + paste

Hi all! How do I cut, copy and paste under unix??? (2 Replies)
Discussion started by: aitor314
2 Replies

9. UNIX Desktop Questions & Answers

Cut, Copy and Paste with X

One of the things that I have learned to take for granted in the Win32 world is the cut, copy and paste hotkeys of ^X, ^C and ^V. I use these keys all the time under Win32 to copy and paste information from one GUI into another GUI. My question is, does X have a similiar standard? ... (4 Replies)
Discussion started by: auswipe
4 Replies
Login or Register to Ask a Question