Identifying specific fields in a Row


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Identifying specific fields in a Row
# 1  
Old 11-25-2010
Java Identifying specific fields in a Row

Hi,

I am new to UNIX. Can some one help me to solve the below.

I have a requirement to to identify the specific fields in row and also some part of the field.

In my file I have a record as
Code:
sundra;10.44.48.65;10thstreet TCP packet out of state: First packet isn't SYN;telno: 21468976;alttelno: 21468977;

and my O/P should be as below.
Code:
sundra,10.44.48.65,10thstreet,21468976,21468977;

Many Thanks in Advance

-Mak

Last edited by Franklin52; 11-25-2010 at 06:13 AM.. Reason: please use code tags
# 2  
Old 11-25-2010
Hi Suneel, welcome to the forum. Would this work?
Code:
sed 's/;/,/g;s/ [^,]*//;s/,[^:,]*: /,/g;s/,$/;/' infile

(on Solaris use /usr/xpg4/bin/sed)
# 3  
Old 11-25-2010
below awk works only on the records having the above format..
Code:
awk -F'[; ]' '{print $1","$2","$3","$14","$16";"}' inputfile > outfile

# 4  
Old 11-25-2010
something like:

Code:
#  nawk -F"[ ;]" '{OFS=",";print $1,$2,$3,$(NF-4),$(NF-1)";"}' infile 
sundra,10.44.48.65,10thstreet,telno:,21468977;

should be reasonable, assuming your file is well formatted.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using awk to change a specific column and in a specific row

I am trying to change the number in bold to 2400 01,000300032,193631306,190619,0640,1,80,,2/ 02,193631306,000300032,1,190618,0640,CAD,2/ I'm not sure if sed or awk is the answer. I was going to use sed and do a character count up to that point, but that column directly before 0640 might... (8 Replies)
Discussion started by: juggernautjoee
8 Replies

2. Shell Programming and Scripting

Analyzing last 2 fields of 1 row and 3rd field of next row

I have the following script that will average the last two fields of each row, but im not sure how to include the 3rd field of the following row. An example of the analysis that I need to perform from the input - (66.61+58.01+54.16)/3 awk '{sum=cnt=0; for (i=13;i<=NF;i++) { sum+=$i; cnt++... (1 Reply)
Discussion started by: ncwxpanther
1 Replies

3. Shell Programming and Scripting

Awk - Script assistance on identifying non matching fields

Hoping for some assistance. my source file consists of: os, ip, username win7, 123.56.78, john win7, 123.56.78, paul win7, 10.1.1.1, john win7, 10.2.2.3, joe I've been trying to run a script that will only return ip and username where the IP address is the same and the username is... (3 Replies)
Discussion started by: tekvaio
3 Replies

4. Shell Programming and Scripting

Identifying entries based on 2 fields in a string.

Hi Guys, I’m struggling to use two fields to do a duplicate/ unique by output. I want to look IP addresses assigned to more than one account during a given period in the logs. So duplicate IP and account > 1 then print all the logs for that IP. I have been Using AWK (just as its installed... (3 Replies)
Discussion started by: wabbit02
3 Replies

5. Shell Programming and Scripting

Date conversion in row while preserving rest of fields

Hi Forum. I searched the forum for a solution but could not find an exact one to my problem. I have some records in the file where I would like to convert the last date field to another format while preserving the rest of the other fields. For example: Found:... (6 Replies)
Discussion started by: pchang
6 Replies

6. Shell Programming and Scripting

To count distinct fields in a row

I have . dat file which contains data in a specific format: 0 3 892 921 342 1 3 921 342 543 2 4 817 562 718 765 3 3 819 562 717 761 i need to compare each field in a row with another field of the same column but different row and cont the... (8 Replies)
Discussion started by: Abhik
8 Replies

7. Shell Programming and Scripting

how to spilit a row into fields and store the field content to the array

consider this is a line A#B#C#D#E#F#G#H note the delimeter is # i want to cut or spilt in to fields using the delimeter # and to store in an array. like this array=A array=B array=C array=D array=E and the array content should be displayed. echo "${array}" echo "${array}"... (5 Replies)
Discussion started by: barani75
5 Replies

8. Shell Programming and Scripting

Insert a text from a specific row into a specific column using SED or AWK

Hi, I am having trouble converting a text file. I have been working for this whole day now, still i couldn't make it. Here is how the text file looks: _______________________________________________________ DEVICE STATUS INFORMATION FOR LOCATION 1: OPER STATES: Disabled E:Enabled ... (5 Replies)
Discussion started by: Issemael
5 Replies

9. Solaris

Identifying new fields of data

i have hundreds of lines of formatted data with 10 different fields per line. the data is refreshed every few minutes and some fields in some lines may reflect new data. i'm looking for a sample of code that help me to identify those new fields so that i can write them to a file to indicate that... (0 Replies)
Discussion started by: davels
0 Replies
Login or Register to Ask a Question