The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to copy and paste line in shell script upsrk Shell Programming and Scripting 14 05-16-2008 07:24 AM
VNC copy paste problem param_it Windows & DOS: Issues & Discussions 0 07-26-2007 11:43 PM
Copy/Paste text as commands in AIX Daniele11 UNIX for Dummies Questions & Answers 1 03-18-2007 04:53 PM
cut, copy + paste aitor314 UNIX for Dummies Questions & Answers 2 02-06-2006 01:17 AM
Cut, Copy and Paste with X auswipe UNIX Desktop for Dummies Questions & Answers 4 03-27-2002 12:27 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-17-2008
Registered User
 

Join Date: Nov 2005
Posts: 22
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-17-2008
Registered User
 

Join Date: Feb 2008
Posts: 12
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
Reply With Quote
  #3 (permalink)  
Old 02-17-2008
Registered User
 

Join Date: Nov 2005
Posts: 22
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
Reply With Quote
  #4 (permalink)  
Old 02-18-2008
Registered User
 

Join Date: Nov 2007
Location: Pune
Posts: 19
Upgrade Sed! your code works fine on lateset sed (4.1.5)
Reply With Quote
  #5 (permalink)  
Old 02-18-2008
Registered User
 

Join Date: Oct 2007
Posts: 73
Quote:
Originally Posted by tiger99 View Post
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
Reply With Quote
  #6 (permalink)  
Old 02-18-2008
Registered User
 

Join Date: Nov 2005
Posts: 22
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
Reply With Quote
  #7 (permalink)  
Old 02-24-2008
Registered User
 

Join Date: Nov 2005
Posts: 22
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.
Could someone please give me some assistant...
Reply With Quote
Google UNIX.COM
Reply

Tags
solaris

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:30 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0