I am very new to to shell scripting and facing a problem that I can't seem to solve. I want to write a bash script that edits file1.txt and saves it as file2.txt.
This is what the files should look like:
file1:
file2:
This is just a short example, there are way more lines. What I want to do is replicate certain lines (and I know what the startline and endline looks like) very often.
I think (unfortunaely I can't test it anymore before tomorrow)
will copy the three lines to a new file file2.txt.
But how can I keep the content of file1.txt and print the three lines to the right position?
Thank you very much! It works fine, but I still have trouble to find out what every part of the code does. What does
for example do? I understand that $0 means the whole line and \n is newline, but what about the X=X in this context?
Is there a way to have the for-loop outside of the awk-command? That would be useful, because later I will need several for-loops around it. I tried things like
But that gives me the whole file three times insted of just a part of it.
X=X $0 "\n"; is a concatenation of X plus $0 plus \n, then assigned to X.
That external for loop will of course print the entire file REPEAT times. If your entire problem were known, it possibly might be solvable entirely in awk.
Thank you! I wanted to keep it simple an face the problem step by step, but that might be confusing, too. So here is the whole problem:
file1.txt is a template that looks like this:
where MM stands for month (0..12) and DD for day (I managed to check with if-constructions how many days one month has. I want to copy and paste the three lines for every month and day, so that I get:
I would do that with two for loops, maybe I will need more in the future for years.
So my initial problem is to copy and paste the three lines. I think I be able to substitute the template MMDD with sed.
Thank you so much! I finally managed to understand every part of your code and could even adapt it as my input has slightly changed to just one line that needs to be copied
This helped me a lot
0
down vote
favorite
I have replicated glusterfs on two servers, if i create file on one server it doesnt reflect on other, if i try to heal the volume on node2 i get this error
Commit failed on node2. Please check log file for details.
glustershd.log
E 0-test-client-3: connection to... (0 Replies)
My first post, so don't kill me :)
Say i open some textfile with some example like this.
on the table are handy, bread and wine
Now i know exactly what is in and i want to separate and sorted it in terminal to an existing file with another 2 existing lines in like this:
table
plane ... (3 Replies)
i am having a text file like below
rama
surya
pandu
latha
singh
raja
i want to get the new file from 3 to 5
i.e
pandu
latha
singh
please help (1 Reply)
Can anyone tell me if it's possible to write a script that will repeat the same job several times but give the output a slightly different name each time (i.e. change or add a number at the end of the output file)? Here is the script I use to run a single job:
#!/bin/bash
#PBS -N job0
#PBS -l... (1 Reply)
if we want to replicate the content of the file twice, then we can use
sed 'p' filename
In the same way, if i want to replicate the content thrice or 4 times, how we can achieve in SED?
Thanks (5 Replies)
I have a textfile containing text similar to the following pattern:
STRING1
UNIQUE_STRING1
STRING2
STRING3
STRING4
STRING5
STRING1
UNIQUE_STRING2
STRING2
STRING3
STRING4
STRING5
STRING1
UNIQUE_STRING3
STRING2
STRING3 (6 Replies)
Morning all,
Is there a command on AIX that can replicate/synchronise two directories? I'm after functionality similar to robocopy on Windows.
Scenario: I have a directory of Oracle forms for my production system and one for my dev system, these directories start off identical.
The forms... (1 Reply)
I'm in the process of setting up two new HP-UX 11.23 i64 servers.
On my existing server (HP-UX B.11.0) we have several users defined to have restricted sam access.
I'm having trouble finding those definitions and copying them over to the new servers. Is this possible - to just copy over the... (1 Reply)