A text file has two logs of same event & both logs have to be correlated into a single line before same can be processed further
RAW
The final column in the first table needs to be looked up in the 2nd table & the matching entry has to be copied to the first table & appended to the end of the Line. Both Tables in the same file. Some entries have extra information, which needs to (Should) be lined up at the end of Line as its length is inconsistent.
Output
Attached a raw file for Simulation.
I have tried with awk & partially successful; but now I am trying for Shell.
As long as the output lines up in columns, do you care whether the output field separators are spaces, tabs, or combinations of spaces and tabs? (Note that your input file has one or two tabs as field separators, and your awk program is using a tab followed by a space as an output field separator.)
Will input data in any field ever contain one or more spaces? If there are spaces in any input field, does that preclude ever using space in an output field separator?
Will the 2nd RunningLog table always contain 3 fields? Or, does you program have to be able to adjust for any number of fields in the 2nd input table?
As long as the output lines up in columns, do you care whether the output field separators are spaces, tabs, or combinations of spaces and tabs? (Note that your input file has one or two tabs as field separators, and your awk program is using a tab followed by a space as an output field separator.)
Will input data in any field ever contain one or more spaces? If there are spaces in any input field, does that preclude ever using space in an output field separator?
Will the 2nd RunningLog table always contain 3 fields? Or, does you program have to be able to adjust for any number of fields in the 2nd input table?
1. Tabs or Spaces doesn't matter, ultimately the output has to go to excel & excel will be able to convert it to Columns on both Tabs/Spaces
2. 2nd Table has around 10 Fields but some fields may or may not carry data, thats why I have tried to copy the complete the line ....
1. Tabs or Spaces doesn't matter, ultimately the output has to go to excel & excel will be able to convert it to Columns on both Tabs/Spaces
2. 2nd Table has around 10 Fields but some fields may or may not carry data, thats why I have tried to copy the complete the line ....
The problem with this is that you want the output columns aligned, but the data in your sample input tables is not aligned:
Code:
RunningLog
Date Month Year Time Event
9 JUN 2013 1932 2
10 JAN 2014 1000 4
Duration Closed
50 Y
11 APR 2013 1230 2
12 FEB 2014 1142 4
13 JAN 2015 0132 3
Duration Closed
40 N
11 FEB 2012 1032 3
END
RunningLog
Event Description Remarks
1 test XXXXX
2 Reset YYYYY
3 Reboot ZZZZZ
4 Unspecified YYYYY
END
I can't align the output if I can't determine what data is in what field in the input. As long as there aren't any empty fields and all fields are separated by one or more tabs (like they are in the 1st table), we can easily align output data. But the 2nd table uses spaces between the 1st two fields and one, two, or three tabs between the 2nd and 3rd fields. If you have ten fields in your 2nd table, it has some empty fields, and uses a combination of spaces and tabs as field separators (or has data in any field that contains characters that are also used as field separators); we can't align the output. (Note that this also applies to the extended fields that appear on some lines. In the sample 1st table, the extended fields have two tabs at the start of the line for each extended header and extended data lines and have one, two, or three tabs separating fields. If these extended lines do not start with whitespace characters, have any empty fields, or use spaces as data with one or more fields and use spaces as field separators; we can't align the output.)
I had a good start on an awk script to gather data, calculate maximum field widths, and print aligned output, but it is useless under these conditions. I'm afraid that I don't see any way to produce code that will align output fields when the input can't be reliably separated into identifiable fields.
P.S. It would have also been nice if you would have warned us that your sample input file (test1.txt) is not a text file. The last four characters in the file are 'E', 'N', 'D', and a <tab> character; there is no <newline> character at the end of the partial line at the end of the file. I was trying to kick off certain actions when I found the END line at the ends of your tables, but some versions of awk completely ignore incomplete lines at the end of a file.
I am trying to use awk to find all the $3 values in file2 that are between $2 and $3 in file1. If a value in $3 of file2 is between the file1 fields then it is printed along with the $6 value in file1. Both file1 and file2 are tab-delimited as well as the desired output. If there is nothing to... (4 Replies)
example of problem:
when I echo "$e" >> /home/cogiz/file.txt
result prints to file as:AA
BB
CC
I need it to save to file as this:AA BB CC
I know it's probably something really simple but any help would be greatly appreciated.
Thank You.
Cogiz (7 Replies)
I have data such as below where the value in second field is the same as that in the row after.
123456,22222,John,0,xyz
234567,22222,John1,1,cde
43212,3333,Jean,3,pip
84324,3333,Abel,2,cat
I'd like to rearrange the output like below to put such records beside each other and separated with... (5 Replies)
performing this code to read from file and print each character in separate line
works well with ASCII encoded text
void
preprocess_file (FILE *fp)
{
int cc;
for (;;)
{ cc = getc (fp);
if (cc == EOF)
break;
printf ("%c\n", cc);
}
}
int
main(int... (1 Reply)
hi Gurus,
I need separate a file which is one huge line to multiple lines based on certain number of charactors. for example:
abcdefghi high abaddffdd
I want to separate the line to multiple lines for every 4 charactors.
the result should be
abcd
efgh
i hi
gh a
badd
ffdd
Thanks in... (5 Replies)
Hi,
I'm getting key-value pairs in a string as follows -
0000xm7zcNDIkP888vRqGv93xA7:176n00qql||9700005405552747,9700005405717924,9700005405733788|unidentified,unidentified,unidentified
I need output as follows -
row1:... (5 Replies)
Hi,
I have a line which has n number of words with separated by space.
I wanted to make each word as a separate line.
for example,
i have a file that has line like
i am a good boy
i want the output like,
i
am
a
good (8 Replies)
I have a text file with 1,000,000 rows (It is a single column text file of numbers). I would like to separate the text file into 100 files of equal size (i.e. number of rows). The first file will contain the first 10,000 rows, the second row will contain the second 10,000 rows (rows 10,001-20,000)... (2 Replies)
I have a large 3479 line .csv file, the content of which looks likes this:
1;0;177;170;Guadeloupe;x
2;127;171;179;Antigua and Barbuda;x
3;170;144;2;Umpqua;x
4;170;126;162;Coos Bay;x
...
1205;46;2;244;Unmak Island;x
1206;47;2;248;Yunaska Island;x
1207;0;2;240;north sea;x... (5 Replies)
Hello UNIX experts,
I have 124 text files in a directory. I want to extract the 45678th line of all the files sequentialy by file names. The extracted lines should be printed in the output file on seperate lines.
e.g. The input Files are one.txt, two.txt, three.txt, four.txt
The cat of four... (1 Reply)