sorting from several files for a specific data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sorting from several files for a specific data
# 1  
Old 11-11-2008
Bug sorting from several files for a specific data

Please assist:

I have several files and all of the files have the same data format like following:
All I need to get item next to "name" field and the "address" field from each file which has only 8 characters in "name" field.



so the output should be:

ams00ark(spcae)10.1.1.12
ams01ark(spcae) 10.1.1.12
per01adp(spcae) 10.1.1.12



start item
name ams00ark
on_off 1
group various
suppress Y
auto_delete N
read_s 123456
write_s 5897856
address 10.1.1.12
terminal 362
icmp_v 5
grade 0
auto_pro 0
time_key_status 0
e-s_ 0
criteria_level 0
end node


start item
name ams01ark
on_off 1
group various
suppress Y
auto_delete N
read_s 123456
write_s 5897856
address 10.1.1.12
terminal 362
icmp_v 5
grade 0
auto_pro 0
time_key_status 0
e-s_ 0
criteria_level 0
end node


start item
name prt00amsten
on_off 1
group various
suppress Y
auto_delete N
read_s 123456
write_s 5897856
address 10.1.1.12
terminal 362
icmp_v 5
grade 0
auto_pro 0
time_key_status 0
e-s_ 0
criteria_level 0
end node



start item
name per01adp
on_off 1
group various
suppress Y
auto_delete N
read_s 123456
write_s 5897856
address 10.1.1.12
terminal 362
icmp_v 5
grade 0
auto_pro 0
time_key_status 0
e-s_ 0
criteria_level 0
end node


Thank you
# 2  
Old 11-11-2008
for i in * ;do echo "" ; cat $i| egrep -i 'name|address' | awk '{print $2}' | tr -s '\n' ' '; echo ""; done

or

Code:
#!/bin/sh

for i in * ;do
        echo ""
        cat $i| egrep -i 'name|address' | awk '{print $2}' | tr -s '\n' ' '
        echo ""
done

# 3  
Old 11-11-2008
Code:
nawk '{
if($1=="name" && length($2)==8)
	t=$2
if($1=="name" && length($2)!=8)
	t=""
if(t!="" && $1=="address")
	print t"  "$2
}' file

# 4  
Old 11-12-2008
The last code is pretty good, since I have multiple files how do I integrate the code, should I put wilcard * , since all of the filename starts with ipcheck. Also in I realized that there are two address field and I need to get address starts with 10.x.x.x.x

Thanks,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting data from specific rows and columns from multiple csv files

I have a series of csv files in the following format eg file1 Experiment Name,XYZ_07/28/15, Specimen Name,Specimen_001, Tube Name, Control, Record Date,7/28/2015 14:50, $OP,XYZYZ, GUID,abc, Population,#Events,%Parent All Events,10500, P1,10071,95.9 Early Apoptosis,1113,11.1 Late... (6 Replies)
Discussion started by: pawannoel
6 Replies

2. Shell Programming and Scripting

Sorting a specific column!

What im trying to do is sort the output by the number on the second column and than limit the result to only the first three lines. This is the code idlist="x23s52; f34233; 2343xs; 25x34; si342d" cntr=1 idcnt=$(print $nidlist |tr ';' '\n' |wc -l) numofgrps=0 while (($cntr <= $idcnt))... (3 Replies)
Discussion started by: ajetangay
3 Replies

3. Shell Programming and Scripting

Converting text files to xls through awk script for specific data format

Dear Friends, I am in urgent need for awk/sed/sh script for converting a specific data format (.txt) to .xls. The input is as follows: >gi|1234|ref| Query = 1 - 65, Target = 1677 - 1733 Score = 8.38, E = 0.6529, P = 0.0001513, GC = 46 fd sdfsdfsdfsdf fsdfdsfdfdfdfdfdf... (6 Replies)
Discussion started by: Amit1
6 Replies

4. UNIX for Dummies Questions & Answers

Sorting columns for specific values

Dear All, i have a column with values in excel table: ATGC22327-p66 ATGC15922-p239 ATGC12710-p21743567 ATGC08037-p186 ATGC07969-p173 ATGC07345-p48534 ATGC02767-p254234 ATGC02124-p2177451 ATGC02124-p1459 ATGC01930-p3005 I need to... (6 Replies)
Discussion started by: AAWT
6 Replies

5. Shell Programming and Scripting

Complex data sorting in excel files or text files

Dear all, I have a complex data file shown below,,,,, A_ABCD_13208 0 0 4.16735 141044 902449 1293900 168919 C_ABCD_13208 0 0 4.16735 141044 902449 1293900 168919 A_ABCDEF715 52410.9 18598.2 10611 10754.7 122535 252426 36631.4 C_DBCDI_1353 0... (19 Replies)
Discussion started by: AAWT
19 Replies

6. Shell Programming and Scripting

Divide data with specific column values into separate files

hello! i need a little help from you :) ... i need to split a file into separate files depending on two conditions using scripting. The file has no delimiters. The conditions are col 17 = "P" and col 81 = "*", this will go to one output file; col 17 = "R" and col 81 = " ". Here is an example. ... (3 Replies)
Discussion started by: chanclitas
3 Replies

7. Programming

Sorting a multidimensional vector by a specific field.

In some cases I would like to sort by index, in some cases by color and in some cases by Callsign. Can this be done? :D vector< vector<string> > table; vector<string> row; row.push_back("1");row.push_back("green");row.push_back("alpha"); table.push_back(row);... (0 Replies)
Discussion started by: sepoto
0 Replies

8. Shell Programming and Scripting

Sorting multi-column values from a specific file

Hi, all. I need a shell script which gathers data from a remote XML file and then displays it according to my needs.. I need this for my job due to the fact that I need to keep track price changes of euro, usd, gold, etc. The XML file I am talking about is located at this page: cnnturk dot... (4 Replies)
Discussion started by: canimsin
4 Replies

9. Shell Programming and Scripting

Need help in writing a script to create a new text file with specific data from existing two files

Hi, I have two text files. Need to create a third text file extracting specific data from first two existing files.. Text File 1: Format contains: SQL*Loader: Release 10.2.0.1.0 - Production on Wed Aug 4 21:06:34 2010 some text ............so on...and somwhere text like: Record 1:... (1 Reply)
Discussion started by: shashi143ibm
1 Replies

10. Shell Programming and Scripting

Extract specific data content from a long list of data

My input: Data name: ABC001 Data length: 1000 Detail info Data Direction Start_time End_time Length 1 forward 10 100 90 1 forward 15 200 185 2 reverse 50 500 450 Data name: XFG110 Data length: 100 Detail info Data Direction Start_time End_time Length 1 forward 50 100 50 ... (11 Replies)
Discussion started by: patrick87
11 Replies
Login or Register to Ask a Question