Extract a number from a line in a file and sed in another copied file
Dear all,
I am trying to extract a number from a line in one file (task 1), duplicate another file (task 2) and replace all instances of the strings 300, in duplicated with the extracted number (task 3). Here is what I have tried so far:
temperatures file:
nvt.mdp file
The result is that I get copies of nvt_1.mdp to nvt_3.mdp correctly, however, I obtain only one copy from task 3 and it is not even named correctly ie. 1_nvt.mdp is only .mdp.
In addition, since the sed command extracts a string from the line, it also extracts with it the line-break "character", changing the formatting of .mdp file.
I realized that if I were to convert the extracted number into an integer it should in theory work to prevent the format change of task 3 files. Though typset -i before Task 1 command gives the error:
")syntax error: invalid arithmetic operator (error token is "
If anyone could help with the proper implementation of task 3 such that formatting of $k_nvt.mdp is not changed and the proper number of copies are generated, I would be very grateful.
Cordially,
Ali
Last edited by Franklin52; 12-12-2010 at 08:46 AM..
Reason: Please use code tags
Ok .. This is driving me nuts. I suppose I need another set of eyes.
Example Data
interface Vlan1
description xxxxxxxxxxxx
ip address 192.168.1.1 255.255.255.252
no ip redirects
no ip proxy-arp
ip flow ingress
ip pim sparse-mode
load-interval 30
!
interface Vlan2
... (5 Replies)
Sed command to replace a line in a file using line number from the output of a pipe.
Is it possible to replace a whole line piped from someother command into a file at paritcular line...
here is some basic execution flow..
the line number is 412
lineNo=412
Now i have a line... (1 Reply)
I have 1 file that has elements as follows. Also the CVR(10) and the word "SAUCE" only appear once in the file so maybe a grep command would work?
file1
CVR( 9) = 0.385E+05, ! VEHICLE
CVR(10) = 0.246E+05, ! SAUCE
CVR(11) = 0.162E+03, ! VEHICLE
I need to extract the... (6 Replies)
Hi,
I search all forum, but I can not find solutions of my problem :(
I have multiple files (5000 files), inside there is this data :
FILE 1:
1195.921 -898.995 0.750312E-02-0.497526E-02 0.195382E-05 0.609417E-05
-2021.287 1305.479-0.819754E-02 0.107572E-01 0.313018E-05 0.885066E-05
... (15 Replies)
I Have file1 with below lines :
#HostNameSelection=0 :NotUsed
#HostNameSelection=1 :Automatic
#HostNameSelection=3 :NotForced
I have file2 which has similar lines but with different values
I want to copy the changes from file1 to file2 ,line by line only if line begins with '#'.
for... (7 Replies)
Hi
I want to extract certain text between two line numbers like
23234234324 and
54446655567567
How do I do this with a simple sed or awk command?
Thank you.
---------- Post updated at 06:16 PM ---------- Previous update was at 05:55 PM ----------
found it:
sed -n '#1,#2p'... (1 Reply)
Hello,
I am having trouble extracting a specific line from a file when the line number is known. My first attempt involved grep -n 'hi' (the word 'hi will always be there) to get the line number before the line that I actually want (line 4).
Extra Notes:
-I am working in a bash script.
-The... (7 Replies)
I have a shell script and want to assign a value to a variable. The value is the line exctrated from a file using the line number. The line number it is not fix, and could change any time.
I have tried sed, awk, head .. See my script
# Get randome line number from the file
#selectedline = `awk... (1 Reply)
Hi,
I have to update last line of a text file with the number of lines in that file. This last line will have text such as 0.0000 and I should replace this with number lines. If lines are 20 then it should be replaced with 00020. Any sed or awk cmd help would be appreciated (3 Replies)