Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
-1.67575986 -0.93463490 -0.04002288 1 1 A
-1.67054931 0.95747993 2.49038750 1 2 A
0.02656904 1.89430566 -0.04319414 1 3 A
1.67890904 0.93354409 2.49318191 1 4 A
1.67546785 -0.94638837 -0.04121474 1 5 A
-0.02566387 -1.89149303 2.48861212 2 6 B
0.03003399 -3.72674086 -0.04296870 2 7 B
-1.53161408 -4.96442186 2.65528205 2 8 B
-3.50360605 -3.83134179 0.12373351 2 9 B
-3.25051789 -1.88832668 2.48613150 3 10 C
-5.07993818 -1.10253852 0.12410003 3 11 C
-5.07980173 1.10605240 2.65639801 3 12 C
I want to add a constant to column three and put the result to the bottom of these columns so that I will have 24 rows at the end. Could anyone let me know how to do it with some shell scripting?
You first need to show us an example of what your desired output would be, and you also need to post what YOU have written and tried so far, and tell us where you're stuck. We will be glad to HELP you, but we're not going to write your scripts for you. There are MANY easily-found scripting tutorials (even one in my posting signature), that can help you get started.
I apologize if my words were like I was asking you to work for me. I give up this question. I just did some manipulations with "cut" and "awk" and could get close to what I wanted.
Sorry again guys.
I apologize if my words were like I was asking you to work for me. I give up this question. I just did some manipulations with "cut" and "awk" and could get close to what I wanted.
Sorry again guys.
Well, all you posted what a few lines of input, and told us what you wanted, and asked for a script. You didn't post what output you wanted, or show us what you did/tried. Certainly SEEMS like you wanted us to write a script for you.
And since you did this, and you came to this site for help, why don't you share your answer, so that others can benefit? And as grail said, we might also be able to improve upon things, too.
Well, all you posted what a few lines of input, and told us what you wanted, and asked for a script. You didn't post what output you wanted, or show us what you did/tried. Certainly SEEMS like you wanted us to write a script for you.
And since you did this, and you came to this site for help, why don't you share your answer, so that others can benefit? And as grail said, we might also be able to improve upon things, too.
well, I really didn't know I am making you guys angry with me. Again I am sorry.Ok, here's what I did:
1. Here's what I wanted as a result:
Code:
-1.67575986 -0.93463490 -0.04002288 1 1 A
-1.67054931 0.95747993 2.49038750 1 2 A
0.02656904 1.89430566 -0.04319414 1 3 A
1.67890904 0.93354409 2.49318191 1 4 A
1.67546785 -0.94638837 -0.04121474 1 5 A
-0.02566387 -1.89149303 2.48861212 2 6 B
0.03003399 -3.72674086 -0.04296870 2 7 B
-1.53161408 -4.96442186 2.65528205 2 8 B
-3.50360605 -3.83134179 0.12373351 2 9 B
-3.25051789 -1.88832668 2.48613150 3 10 C
-5.07993818 -1.10253852 0.12410003 3 11 C
-5.07980173 1.10605240 2.65639801 3 12 C
-1.67575986 -0.93463490 0.95997712 1 13 A
-1.67054931 0.95747993 3.49038750 1 14 A
0.02656904 1.89430566 0.95997712 1 15 A
1.67890904 0.93354409 3.49318191 1 16 A
1.67546785 -0.94638837 0.95997712 1 17 A
-0.02566387 -1.89149303 3.49318191 2 18 B
0.03003399 -3.72674086 0.95997712 2 19 B
-1.53161408 -4.96442186 3.49318191 2 20 B
-3.50360605 -3.83134179 1.12373351 2 21 B
-3.25051789 -1.88832668 3.48613150 3 22 C
-5.07993818 -1.10253852 1.12410003 3 23 C
-5.07980173 1.10605240 3.65639801 3 24 C
2. First I took columns #1,2,3,4,5 and #6 out with awk to separate files:
Quote:
awk '{print $1}' input > output1
3. I added 1 to the numbers of the column #3 in file3:
Quote:
awk '{print ($1 +1)}' output3 > output33
This way I had the digits for column three ready.
4. I merged the columns #1,2,3,4 with paste command:
Quote:
paste output1 output2 output3 output4 > output-1
5. I appended the merged file to the first file using cat (I had removed columns 5 and 6 with cut):
Quote:
cat output-1 >> input
(columns #1 to #4 were ready for the result I wanted)
also appended column #6 using cat again in a separate file:
Quote:
cat output6 >> output6
6. for column #5, I just put the line numbers as below:
Quote:
awk '{ print NR" "$0 }' input
Then "cut" this column in a seperate file and merged everything again using "paste"
I should say that before I join this forum, I read the terms of asking questions and I did not mean to insult anyone. I'll go back and read the terms of asking questions again because I like this forum really very much and I want to keep asking questions.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.