Copy/Paste data in files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Copy/Paste data in files
# 1  
Old 12-14-2009
Copy/Paste data in files

Hi,
I want to put the following values into Variables R2=0.999863 , V2=118.870318 , D2=-178.887511 and so on. There are six values for each variable R2-R8, V2-V8 and D2-D8, total of 18 values for all the variables. Can any one help me to copy and paste all the values in their respective variables by using a single command like 'awk' within a file and from one file to another? I have tried using vi editor but in vain.
Thanks in advance

H 0.999863 118.870318 -178.887511
H 1.069135 110.154927 -121.929
H 0.998360 120.087739 178.779
H 1.070568 109.464359 -109.118910
H 1.069487 109.485378 10.786746
H 1.068826 109.494543 130.888378


H R2 V2 D2
H R3 V3 D3
H R4 V4 D4
H R6 V6 D6
H R7 V7 D7
H R8 V8 D8

Variables:
R2=
R3=
R4=
R6=
R7=
R8=
V2=
V3=
V4=
V6=
V7=
V8=
D2=
D3=
D4=
D6=
D7=
D8=
# 2  
Old 12-14-2009
Wrench

Try inline perl if that helps

Code:
 cat abc.txt | perl -e '
$i=2;
while(<>){
chomp ;
($h,$hash{r}{$i},$hash{v}{$i},$hash{d}{$i}) = split(" ");
$i++;
}
for my $i (2..8){
for my $var ('r','v','d'){
        print uc($var)."$i=$hash{$var}{$i}\n";

}
}
'

HTH,
PL

Last edited by daptal; 12-14-2009 at 10:55 PM.. Reason: change in the for loop to include 8
# 3  
Old 12-15-2009
Code:
#!/usr/bin/bash

i=2
while read LINE
do
  set -- $LINE
  eval R$i=$2
  eval V$i=$3
  eval D$i=$4
  let i=$i+1
done < date.txt

# Sample output
echo $R2,$V5,$D7

0.999863,109.464359,130.888378
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to copy particular files from a multiple directories and paste in a new directory?

Dear all I have a multiple directories, say for example org1, org2, org3 ..... org100 and each directory having a file namely dnaG.fasta. I need to copy all the dnaG.fasta file from each directory and paste in another directory fastconcatg. Therefore, my script has to copy dnaG.fasta file from... (5 Replies)
Discussion started by: dineshkumarsrk
5 Replies

2. UNIX for Beginners Questions & Answers

How to copy a column of multiple files and paste into new excel file (next to column)?

I have data of an excel files as given below, file1 org1_1 1 1 2.5 100 org1_2 1 2 5.5 98 org1_3 1 3 7.2 88 file2 org2_1 1 1 2.5 100 org2_2 1 2 5.5 56 org2_3 1 3 7.2 70 I have multiple excel files as above shown. I have to copy column 1, column 4 and paste into a new excel file as... (26 Replies)
Discussion started by: dineshkumarsrk
26 Replies

3. UNIX for Beginners Questions & Answers

Copy data at specified location from multiple files

Hello everyone, Im super new to coding but increasingly in need of it at work. Im have task stacked because of this problems, that I cannot figure out how to solve looking on the internet after trying many many things that looked similar to me. I have multiple data files of the form (see below).... (2 Replies)
Discussion started by: Xfiles_fan
2 Replies

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

5. Shell Programming and Scripting

Copy and paste data

I need to copy from specified lines and paste the data into several other lines. XX123450008 xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x XX123451895 xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x ...... XX123452012 xx.x xx.x xx.x xx.x xx.x xx.x xx.x... (13 Replies)
Discussion started by: ncwxpanther
13 Replies

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

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

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

Search, copy and paste

Can i search in a file for more than one string at a time? And copy the next string after that and paste it in column style? Is it possible? Thanks! (4 Replies)
Discussion started by: kingpeejay
4 Replies

10. 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
Login or Register to Ask a Question