Results 1 to 10 of 23
Hi,
I have a file that each line starts with a device name and the rest of the line is status data.
Then I have a series of individual files ...
- 06-12-2010 #1Just Joined!
- Join Date
- Mar 2008
- Posts
- 20
File Updating help needed
Hi,
I have a file that each line starts with a device name and the rest of the line is status data.
Then I have a series of individual files that actually have the most recent data for some of those devices in the main file.
What I am trying to do is update the main file that is used by everyone with the updated track files. This has been a manual operation for too long.
The device line in the main file and the device line in the updated file start the same.
i.e. 1 25544 or 1 23952 or 1 10110
objective here is to pull over the entire line from the update file and put it in its place as the main file on its existing line.
I can grep the data line that needs to be replaced and I can grep the updated line in file2 that I want to replace the old data with. My confusion is how to use sed or another way and to do this to move an entire line of dynamic data.
The data is dynamic Only the first 7 characters are static. It has to go in the same location on the main file.
Thanks in advance for any help .Last edited by ml41782; 06-12-2010 at 12:37 PM. Reason: typos
- 06-13-2010 #2
Please post samples of the files, abbreviated if necessary (and use [code] tags to preserve formatting; this is important). How are the individual files associated with the contents summary file? Is there always one individual file for each entry in the summary file?
What kind of system are you looking for; bash? perl? C? Other/don't care?
--- rod.Stuff happens. Then stays happened.
- 06-13-2010 #3Just Joined!
- Join Date
- Mar 2008
- Posts
- 20
file update help needed
I found I can use sed and manipulate indiviual items in the line but not replace the entire line of code with the new data.
Here is a snippet from the main file.
satfile.tle
HUBBLE
1 20580U 90037B 10160.79995157 .00000418 00000-0 19150-4 0 5825
2 20580 028.4719 288.0856 0003457 118.4019 241.6867 15.00984670903644
ISS
1 25544U 98067A 10161.90293064 .00007708 00000-0 62806-4 0 3028
2 25544 051.6490 262.7699 0008898 308.1047 157.6396 15.71753274662489
CO-58
1 28895U 05043F 10160.71634712 .00000240 00000-0 59432-4 0 06050
2 28895 098.0195 045.4427 0016956 312.2023 047.7722 14.59899315245893
NO-44
1 26931U 01043C 10160.64834270 -.00000230 00000-0 -57579-4 0 4787
2 26931 067.0517 223.3971 0005590 265.1976 094.8477 14.29598500453678
SO-50
1 27607U 02058C 10161.55233805 .00000088 00000-0 35644-4 0 1957
2 27607 064.5584 016.6711 0034671 080.0705 280.4311 14.71546567401403
Here is is the file to replace both of the ISS lines
iss.loc
1 25544U 98067A 10162.85578863 .00009727 00000-0 77933-4 0 3071
2 25544 051.6500 257.8926 0008747 312.4914 148.5140 15.71779028662631
same as this file
no44.loc
1 26931U 01043C 10162.11751480 -.00000283 00000-0 -78274-4 0 4796
2 26931 067.0516 219.6122 0005569 264.4937 095.5520 14.29597784453881
- 06-13-2010 #4Just Joined!
- Join Date
- Mar 2008
- Posts
- 20
Trying to do this all in bash.
- 06-13-2010 #5
So, before we can proceed, we need the answer to all of the questions. I will be more detailed about what we need to know. Is the filename always/never embedded in the file (you could have indicated this by using [code] tags in your samples, like I asked)?You gave us
iss.loc
1 25544U 98067A 10162.85578863 .00009727 00000-0 77933-4 0 3071
2 25544 051.6500 257.8926 0008747 312.4914 148.5140 15.71779028662631
Does the file named iss.loc look like
orCode:1 25544U 98067A 10162.85578863 .00009727 00000-0 77933-4 0 3071 2 25544 051.6500 257.8926 0008747 312.4914 148.5140 15.71779028662631
How do we know which files are involved? All files that are not named 'satfile.tle'? All files that we name on a commandline? All files whose contents match some format or pattern? The headings in the summary file seem to match somewhat the names of the files. Is there any pattern about how to relate these, or is that irrelevant?Code:iss.loc 1 25544U 98067A 10162.85578863 .00009727 00000-0 77933-4 0 3071 2 25544 051.6500 257.8926 0008747 312.4914 148.5140 15.71779028662631
You mention that the first 7 characters of each record are static (whatever that means), but they are not unique in either the individual file or the summary file. Are we somehow supposed to used those as keys for the rest of the lines?
These are not unique keys.Code:cut -c -7 satfile.tle HUBBLE 1 20580 2 20580 ISS 1 25544 2 25544 CO-58 1 28895 2 28895 NO-44 1 26931 2 26931 SO-50 1 27607 2 27607
As I look at what I have so far, this looks like it is best done with more than just bash. Is bash a hard requirement? What about wrapping Perl or awk code in a bash script?
Please answer everything. No one can read your mind to determine the requirements.
--- rod.Stuff happens. Then stays happened.
- 06-13-2010 #6
Oops, my bad! I see that the first characters actually are unique. So, I guess those are to be used as the keys for replacement of the rest of the records?
--- rod.Stuff happens. Then stays happened.
- 06-13-2010 #7Just Joined!
- Join Date
- Mar 2008
- Posts
- 20
I'm sorry.
The file name is never embedded in the file itself.
I can use a combination to accomplish this. I attempted to use awk and sed to do this but my coding didn't work.
This was one of my tests that failled. well they all did but..
awk '/"1 25544"/{getline s < "iss.loc"; $0=$1 FS s FS k}1' digi_ned.tle > newfile
The main file used is satfile.tle. This is used by the program 24 /7 to get updated information and send it out based on requests. the .loc files are update files with new tradjectory information. This is handled today as a manual update each morning. Then a command is issued to update the tle data to the system.
The file name iss.loc
<begin>
1 25544U 98067A 10162.85578863 .00009727 00000-0 77933-4 0 3071
2 25544 051.6500 257.8926 0008747 312.4914 148.5140 15.71779028662631
<end>
nothing more than the 2 lines in the file. no header line
file name satfile.tle (snippett)
Just these three lines per each sat in this file. nothing more
<begin>
HUBBLE
1 20580U 90037B 10160.79995157 .00000418 00000-0 19150-4 0 5825
2 20580 028.4719 288.0856 0003457 118.4019 241.6867 15.00984670903644
ISS
1 25544U 98067A 10161.90293064 .00007708 00000-0 62806-4 0 3028
2 25544 051.6490 262.7699 0008898 308.1047 157.6396 15.71753274662489
CO-58
1 28895U 05043F 10160.71634712 .00000240 00000-0 59432-4 0 06050
2 28895 098.0195 045.4427 0016956 312.2023 047.7722 14.59899315245893
NO-44
1 26931U 01043C 10160.64834270 -.00000230 00000-0 -57579-4 0 4787
2 26931 067.0517 223.3971 0005590 265.1976 094.8477 14.29598500453678
SO-50
1 27607U 02058C 10161.55233805 .00000088 00000-0 35644-4 0 1957
2 27607 064.5584 016.6711 0034671 080.0705 280.4311 14.71546567401403
<end>
Mike
- 06-13-2010 #8
Okay, since I screwed up, I decided to take a shot at a solution based on my best guess at your requirements:
Run this, and the result should be in 'satfile.tle.TMP'. Expects all files to be in the current working directory.Code:#! /bin/sh # # LFml41782.sh # summaryFileOrg="satfile.tle" summaryFile="$summaryFileOrg.TMP" cp $summaryFileOrg $summaryFile for file in *.loc; do if [ $file != $summaryFile ]; then echo $file while read record; do key=$(echo $record | cut -c -7) echo "Key: " $key value=$(echo $record | cut -c 8-) echo "Value: "$value sed -i -e "/$key/ s/$key.*/$key$value/" $summaryFile done < $file fi done diff $summaryFileOrg $summaryFile
--- rod.Stuff happens. Then stays happened.
- 06-13-2010 #9Just Joined!
- Join Date
- Mar 2008
- Posts
- 20
Rob,
Thanks tHis is so close. I can't seem to figure out why the data has shifted on the temp file. This is position sensitive. When I look at your code I see you looking at the first 7 ( The unique ID) and then 8- for the data. It doesn't explain the shift as you see it below. I did a grep on all three points. The strange thing here is that line 2 appears to be OK .
Thanks for your help so far
Mike
server test # cat satfile.tle.TMP | grep 25544
1 25544U 98067A 10162.85578863 .00009727 00000-0 77933-4 0 3071
2 25544 051.6500 257.8926 0008747 312.4914 148.5140 15.71779028662631
server test # cat iss.loc
1 25544U 98067A 10162.85578863 .00009727 00000-0 77933-4 0 3071
2 25544 051.6500 257.8926 0008747 312.4914 148.5140 15.71779028662631
server test # cat satfile.tle | grep 25544
1 25544U 98067A 10161.90293064 .00007708 00000-0 62806-4 0 3028
2 25544 051.6490 262.7699 0008898 308.1047 157.6396 15.71753274662489
server test # cat satfile.tle | grep 26931
1 26931U 01043C 10160.64834270 -.00000230 00000-0 -57579-4 0 4787
2 26931 067.0517 223.3971 0005590 265.1976 094.8477 14.29598500453678
server test # cat no44.loc
1 26931U 01043C 10162.11751480 -.00000283 00000-0 -78274-4 0 4796
2 26931 067.0516 219.6122 0005569 264.4937 095.5520 14.29597784453881
server test # cat satfile.tle.TMP | grep 26931
1 26931U 01043C 10162.11751480 -.00000283 00000-0 -78274-4 0 4796
2 26931 067.0516 219.6122 0005569 264.4937 095.5520 14.29597784453881
server test #
- 06-13-2010 #10Just Joined!
- Join Date
- Mar 2008
- Posts
- 20
Its works
Thank you for putting me in the right direction.
This was the fix. As you can see I had to modify the cut lines.
#! /bin/sh
#
# LFml41782.sh
#
summaryFileOrg="satfile.tle"
summaryFile="$summaryFileOrg.TMP"
cp $summaryFileOrg $summaryFile
for file in *.loc; do
if [ $file != $summaryFile ]; then
echo $file
while read record; do
key=$(echo $record | cut -d' ' -f -
echo "Key: "$key
value=$(echo $record | cut -d' ' -f 9-)
echo "Value: "$value
sed -i -e "/$key/ s/$key.*/$key$value/" $summaryFile
done < $file
fi
done
diff $summaryFileOrg $summaryFile
server test # cat satfile.tle.TMP | grep 25544
1 25544U 98067A 10161.90293064 .00007708 00000-0 62806-4 0 3028
2 25544 051.6490 262.7699 0008898 308.1047 157.6396 15.71753274662489
server test # cat iss.loc
1 25544U 98067A 10162.85578863 .00009727 00000-0 77933-4 0 3071
2 25544 051.6500 257.8926 0008747 312.4914 148.5140 15.71779028662631
server test # cat satfile.tle | grep 25544
1 25544U 98067A 10161.90293064 .00007708 00000-0 62806-4 0 3028
2 25544 051.6490 262.7699 0008898 308.1047 157.6396 15.71753274662489


Reply With Quote