I am new to Linux and have a challenging task.
I have 3 data files, and need to do the following:
Go to line 31 of file 1, delete it
Read 1 line from file 2 and add in place of deleted line
Go to line 97 of file I delete it and then read the line 1 from file 2 and add in place of that deleted file.
The thing is also important to keep the same file i.e file , it is not to be changed.
I tried different versions of sed and perl, with buffer copying tricks but was not successful.
I am open for all suggestions and request the experts to give me suggestions.
Well, it's very clunky, but you could try:-
Does that do it? I feel a proper sed or awk would be better if the files are large. Additionally, remember the vi has limitation such as maximum line length and space for the temporary files it uses, often in /var
You could also:-
You would need to check the exact records this catches as head & tail vary accourding to OS version. You also cannot write this back to file1 until you have created the replacement file, so you might hit space issues.
Could you expand on the reasons for the edit and sizes of files etc.
I hope that this helps if it's a small enough file to be processed each time.
Robin
Liverpool/Blackburn
UK
Last edited by rbatte1; 02-09-2012 at 12:38 PM..
Reason: Added another option
I am trying to make my script as simple as a possible but, I am not sure if the way I am approaching is necessarily the most efficient or effective it can be. What I am mainly trying to fix is a for loop to remove a string from the specified files and within this loop I am trying to copy the lines... (2 Replies)
I'm trying to do this exact same thing, so far I have created this to move files
i've named my script CP.sh
#!/bin/bash
cd /root/my-documents/NewDir/
for f in *.doc
do cp -v $f root/my-documents/NewDir $f{%.doc}
done
When i go to run this in the console i type, bin/sh/ CP.sh
but it... (7 Replies)
Hi all
I have a requirement
I need to copy only first 2 lines from a file of one location to another file of same location
I used to code as
cp head -2 abc 123
But i get the following error
cp: 0653-437 123 is not a directory.
The files used are
cat abc
ABCD
EFDG
TYUI (5 Replies)
Hello All,
I want to copy some lines from one file to other with following condition.
Only lines between two specified strings should copy.
Example :-
"My First String "
Some_Other_String ....
Some_Other_String ....
Some_Other_String ....
"My Second String"
So only... (5 Replies)
Hi folks! I'm new to the unix-side of the world! ;) and I'm trying to learn as much as possible the good stuff that's in it!
So.. here comes the point.. as you can see in the title, I need to copy a file but truncating it so that last 1-2 lines are not copied... any suggests from the... (6 Replies)
Hi All,
I am doing this for svn patch making. I got the list of files to make the patch. I have the list in a file with path of all the files.
To Do
From Directory : /myproject/MainDir
To Directory : /myproject/data
List of files need to copy is in the file: /myproject/filesList.txt
... (4 Replies)
I am userB and have a dir
/temp1
This dir is owned by me.
How do I recursively copy files from another users's dir userA?
I need to preserve the original user who created files, original group information, original create date, mod date etc.
I tried
cp -pr /home/userA/* .
... (2 Replies)
Hi I'm in the need of a script that basically takes two files and generates a 3rd. It reads from fileA and fileB and copies lines from fileA if they start by a word of fileB.
for example
fileA
The dog is beautful
Where is your cat
Why are you sad?
Help me!
fileB
The
Where
tree
dog... (4 Replies)