How to copy and paste line in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to copy and paste line in shell script
# 15  
Old 05-16-2008
Code:
sed '/host=atlx3  *sid=atld3 mail=/{;h;s/mail=.*/mail=DISABLE/p;x;s/^/#/;}' abc.txt

There are two spaces and an asterisk between host and sid now. space asterisk means zero or more spaces, so makes multiple spaces optional.
# 16  
Old 10-01-2008
MySQL Grep Words,Cut and the prepare a string

AU Main Date: 08-SEP-08 10:27:11
Profit and Loss Long Report Page: 1
Current Period: AUG-08

Personal Unit=AU003 (Industrial Products Division),Plant=B00089,Departmant=D110
Ptd-Actual Ptd-Budget Ptd-Variance YTD-Actual YTD-Budget YTD-Variance
Account Le BU Pl De In Fu
------------------------------ -- -- -- -- -- -- ------------ ------------ ------------ -------------- ------------- ------------
Operating Distribution 0.00 0.00 0.00 -30,808,210.75 0.00 30808210.75

Cost of Sales/OPNS 180,689.57 0.00 -180,689.57 173818430.54 0.00 -173818430.54

GROSS PROFIT 180,689.57 0.00 -180,689.57 -118521808.49 0.00 118521808.49

Marketing Distrib 0.00 0.00 0.00 0.00 0.00 0.00

Personal Unit=AU004 (Industrial Products Division),Plant=B01189,Departmant=D111


Ptd-Actual Ptd-Budget Ptd-Variance YTD-Actual YTD-Budget YTD-Variance
Account Le BU Pl De In Fu
------------------------------ -- -- -- -- -- -- ------------ ------------ ------------ -------------- ------------- ------------
Operating Distribution 0.00 0.00 0.00 -30,808,210.75 0.00 30808210.75

Cost of Sales/OPNS 180,689.57 0.00 -180,689.57 173818430.54 0.00 -173818430.54

GROSS PROFIT 180,689.57 0.00 -180,689.57 -118521808.49 0.00 118521808.49

Marketing Distrib 0.00 0.00 0.00 0.00 0.00 0.00





I need oput where ever i find Personal unit just capture that line and copy that line to make it like


Personal Unit=AU003
Plant=B00089
Departmant=D110
-->RAM:AU003:B00089Smilie110:08-SEP-08:US Primary


I am using

sed -e '/Personal Unit/{;h;s/^/#/p;x;}' -e '/Business Unit/{s/,Plant/\nPlant/g' -e 's/,Departmant/\nDepartmant/g'} filename

But this is not fulfilling my requirement
Any one please help me on this
# 17  
Old 10-02-2008
Quote:
Originally Posted by krishna.fuji
AU Main Date: 08-SEP-08 10:27:11
Profit and Loss Long Report Page: 1
Current Period: AUG-08

Personal Unit=AU003 (Industrial Products Division),Plant=B00089,Departmant=D110
Ptd-Actual Ptd-Budget Ptd-Variance YTD-Actual YTD-Budget YTD-Variance
Account Le BU Pl De In Fu
------------------------------ -- -- -- -- -- -- ------------ ------------ ------------ -------------- ------------- ------------
Operating Distribution 0.00 0.00 0.00 -30,808,210.75 0.00 30808210.75

Cost of Sales/OPNS 180,689.57 0.00 -180,689.57 173818430.54 0.00 -173818430.54

GROSS PROFIT 180,689.57 0.00 -180,689.57 -118521808.49 0.00 118521808.49

Marketing Distrib 0.00 0.00 0.00 0.00 0.00 0.00

Personal Unit=AU004 (Industrial Products Division),Plant=B01189,Departmant=D111


Ptd-Actual Ptd-Budget Ptd-Variance YTD-Actual YTD-Budget YTD-Variance
Account Le BU Pl De In Fu
------------------------------ -- -- -- -- -- -- ------------ ------------ ------------ -------------- ------------- ------------
Operating Distribution 0.00 0.00 0.00 -30,808,210.75 0.00 30808210.75

Cost of Sales/OPNS 180,689.57 0.00 -180,689.57 173818430.54 0.00 -173818430.54

GROSS PROFIT 180,689.57 0.00 -180,689.57 -118521808.49 0.00 118521808.49

Marketing Distrib 0.00 0.00 0.00 0.00 0.00 0.00





I need oput where ever i find Personal unit just capture that line and copy that line to make it like


Personal Unit=AU003
Plant=B00089
Departmant=D110
-->RAM:AU003:B00089Smilie110:08-SEP-08:US Primary


I am using

sed -e '/Personal Unit/{;h;s/^/#/p;x;}' -e '/Business Unit/{s/,Plant/\nPlant/g' -e 's/,Departmant/\nDepartmant/g'} filename

But this is not fulfilling my requirement
Any one please help me on this
This is a duplicate of this post:

https://www.unix.com/shell-programmin...#post302242263

No duplicate or cross-posting, please read the:

https://www.unix.com/unix-dummies-que...om-forums.html.

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

Paste command not working in shell script

Hai , When i use paste command in command prompt its giving expected output but not in the script. Below is the example. $cat file 1 2 3 $cat file1 4 5 6 $paste -d ':' file file1 1:4 2:5 3:6 but when i used the same command in script its giving the output as below : 1 2 3 (3 Replies)
Discussion started by: Subbu123
3 Replies

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

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

5. Shell Programming and Scripting

Copy and Paste to a new document

Hello, I am quite new to shell scripting so don't know all the tools available. What I'm trying to do is open a file optimal.txt search for objectiveValue and copy the number in quotes next to it. e.g. ... solutionName="incumbent" solutionIndex="-1" objectiveValue="13246" ... (6 Replies)
Discussion started by: StephanR
6 Replies

6. UNIX for Dummies Questions & Answers

Copy/Paste in Vi editor

Dear All, I have a file containing 12 lines. First 3 lines have 9 values and the remaining 9 lines with no values. I was trying to copy and paste these 9 values of the first 3 lines into last 9 lines simultaneously as A=1.491331, B=1.539000 ..... but I don't know how to cope with this... (9 Replies)
Discussion started by: sullah
9 Replies

7. Shell Programming and Scripting

Help with a shell script to modify one line and copy the next 9 to same file

Hi everyone, the problem is quite simple, yet I can't find an easy solution using awk. I need to search for a string in $3, then if I find this string, copy the line,modify $3, and copy the next 9 lines to the same file. My problem is in the copying of the lines... Finding and modifying... (5 Replies)
Discussion started by: Teroc
5 Replies

8. Shell Programming and Scripting

copy/paste with awk

Hi everybody, I have two XML files. I am working on a script that could copy and paste the contents of the first xml file to the desired location in the second xml file. Here is my first XML file. This is the second XML file. Finaly, I wnat to obtain something like that : ... (2 Replies)
Discussion started by: lsaas
2 Replies

9. Shell Programming and Scripting

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:... (7 Replies)
Discussion started by: tiger99
7 Replies
Login or Register to Ask a Question