so there are many lines like the 3rd and the 7th lines
there are many fields in these lines, separated by '\t'
and I want to extract the fields and put them into different log files.
for example, in hosts.log, I will have
hosts.log is special coz there are sub-fields separated by ','
in Seq_Index.log, I will have
in ip_id.log,I will have
Quote:
Originally Posted by pamu
Its depend on what you want to achieve.
Please provide some more lines of your input.
so there are many lines like the 3rd and the 7th lines
there are many fields in these lines, separated by '\t'
and I want to extract the fields and put them into different log files.
for example, in hosts.log, I will have
hosts.log is special coz there are sub-fields separated by ','
in Seq_Index.log, I will have
in ip_id.log,I will have
Your input sample above has spaces instead of tabs, but I think I changed appropriate spaces to tab characters to produce a test file.
Above you say that hosts.log has subfields separated by <comma>, but the only field name that contains comma separated subfields is the field that starts with "Ports:". Assuming you meant Ports instead of Hosts, I think the following script will do what you said you want:
Note that this code doesn't care what the field names are in your input, it will determine what they are on the fly. For each field name it finds (either at the start of a line or after a tab up to the first <colon><space> after that) it creates a file with the name found (after changing any spaces to underscores). It will produce separate lines in the log files for each <comma><space> separated subfield it finds no matter what the field name is. With the input shown above, this script produces the log files: Host, IP_ID_Seq, Ignored_State, Ports, Seq_Index, and Status.
It isn't obvious to me that these log files are going to be useful since there is no time stamp on any of the entries and there is no way to connect entries in any of these files (except Host) to the name of host associated with the entry. Maybe you want to capture some data from some of the comment lines to include at the beginning of each line printed to the log files, or maybe you don't want a Host file, but instead want to start each line in the remaining log files with the name from the Host: field at the start of each non-comment line.
Note also that if there is a large number of different field names (each of which produces a different log file), awk may run out of file descriptors. If that is an issue, there are several ways it can be alleviated, but the script will run slower since it may need to close and reopen output files frequently.
My file looks like
3 33 210.01.10.0 2.1 1211 560 26 45 1298 98763451112 15412323499 INPUT OK
3 233 40.01.10.0 2.1 1451 780 54 99 1876 78787878784 15423210199 CANCEL OK
Aim is to replace the spaces in each line by tab
Used: sed -e 's/ */\t/g'
But I get output like this... (3 Replies)
I have a variable sumOfJEOutputFile which is the output file of an SQL command which contains the output of that SQL. The output looks like below:
-----------
58
I am using following code to manipulate the output:
(sed 1,2d $sumOfJEOutputFile > $newTemp1 | sed '$d' $newTemp1)... (4 Replies)
Hi,
I have a space delimited text file but I only want to change the first space to a tab and keep the rest of the spaces intact. How do I go about doing that? Thanks! (3 Replies)
Hello,
Is there a direct command to check if the delimiter in your file is a tab or a space? And how can they be converted from one to another.
Thanks,
G (4 Replies)
Hi,
So my file looks like this:
title number
JR 2
JR 2
JR 4
JR 5
NM 5
NM 8
NM 2
NM 8
I used this line that I wrote to convert it to rows so it will look like this:
awk -F"\t" '!/^$/{a=a" "$3} END {for ( i in a) {print i,a}}' occ_output.tab > test.txt
JR 2 2 4 5
NM 5 8... (4 Replies)
Wants to print line when there exist leading or trailing space or tab in fields 2,3 and 5
The below code prints all lines in file even if they dont have leading and trailing space or tab.
nawk -F"|" '{for(i=1;i<=NF;i++) {if ($i ~ "^*" || $i ~ "*$")}}1' file
file
Ouput required:
... (5 Replies)
i have a commad that display the total each directory size in KB.Below the commad and o/p:
ls -ltr | grep ^d | awk '{print $9}' | xargs du -sk
output:
what i want is the proper tab space b/w value and dir.? how to get that.
thanks in advance (10 Replies)
I'm reading from a file that is semi-colon delimited. One of the fields contains 2 spaces separating the first and last name (4th field in - "JOHN<space><space> DOE"):
e.g. TORONTO;ONTARIO;1 YONGE STREET;JOHN DOE;CANADA
When I read this record and either echo/print to screen or write to... (4 Replies)