Shell script to search through numbers and print the output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to search through numbers and print the output
# 8  
Old 10-30-2007
Replace :
Code:
         Values[j] = (i==1 && j==1 ? "" : Values[j] OFS) substr($0, j-from+1, 1);

by :
Code:
         Values[j] = (i==1 && j==1 ? "" : Values[j] OFS) $(j-from+1);

Jean-Pierre.
# 9  
Old 10-30-2007
If I understand correctly 8 should be in 2 :

Code:
awk 'NR == FNR { x[$1]; next }
NF { 
	for ( i in x ) 
		x[i] = x[i] ? x[i] " " $i : $i 
	} END {
		for ( j in x )
			print j, x[j]
}' file2 file1


Code:
$ cat file1


1 8

A G H H H U I O
22 33 44 55 32 53 4 55


$ cat file2
2
4
6
$ nawk 'NR == FNR { x[$1]; next }
NF { 
for ( i in x ) 
x[i] = x[i] ? x[i] " " $i : $i 
}END{
for ( j in x )
print j, x[j]
}' file2 file1
2 8 G 33
4 H 55
6 U 53

I'm not sure about the requirement,
but if the output should be really as shown:

Code:
$ nawk 'NR == FNR { x[$1]; next }
NF > 2 { 
for ( i in x ) 
x[i] = x[i] ? x[i] " " $i : $i 
}END{
for ( j in x )
print j, x[j]
}' file2 file1
2 G 33
4 H 55
6 U 53

Use nawk or /usr/xpg4/bin/awk on Solaris.

Last edited by radoulov; 10-30-2007 at 06:48 PM.. Reason: sure I'm missing something :)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need shell script to Telnet multiple node , Ping some IP and print output

Hi Team, Need shell script to Telnet multiple node , Ping some IP and print output like pass or fail. Need this script to check reachability of multiple nodes at same time. Help me. I use this but not working... Eg. in this script i need to telnet... (4 Replies)
Discussion started by: Ganesh Mankar
4 Replies

2. Shell Programming and Scripting

Need to Print output in table using shell script

#! /bin/ksh #] && . ./.profile 2>/dev/null if test -f '.profile'; then . ./.profile; fi; #. .profile LOG_DIR=/app/rpx/jobs/scripts/just/logs sendEmail() { pzCType="$1"; pzTitle="$2"; pzMsg="$3"; pzFrom="$4"; pzTo="$5"; pzFiles="$6"; pzReplyTo="$7" ( ... (4 Replies)
Discussion started by: ankit.mca.aaidu
4 Replies

3. Shell Programming and Scripting

awk script to search output for a value and print

GOODNUMBERS="1 2 3 4 5 6 3 3 34 34 5 66 12" BADNUMBERS="7 3 12 5 66" for eachnum in `echo ${GOODNUMBERS}` do echo ${BADNUMBERS} | gawk -v threshold=${eachnum} '$1 != threshold' done what im trying to do with the above is, i want to print numbers that are in the GOODNUMBERS... (10 Replies)
Discussion started by: SkySmart
10 Replies

4. Shell Programming and Scripting

How to print the output of a select query using shell script?

HI, I want to connect to database and fetch the count from a table. The sql query is as below : select count(*) from table_test where test_column='read'; How can I print the output of this statement using shell script. Thanks in advance. (4 Replies)
Discussion started by: confused_info
4 Replies

5. Shell Programming and Scripting

Shell script to search a pattern in a directory and output number of find counts

I need a Shell script which take two inputs which are 1) main directory where it has to search and 2) pattern to search within main directory all files (.c and .h files) It has to print number of pattern found in main directory & each sub directory. main dir --> Total pattern found = 5 |... (3 Replies)
Discussion started by: vivignesh
3 Replies

6. UNIX for Advanced & Expert Users

Shell Script to compare xml files and print output to a file

All, PLease can you help me with a shell script which can compare two xml files and print the difference to a output file. I have attached one such file for you reference. <Group> <Member ID=":Year_Quad:41501" childCount="4" fullPath="PEPSICO Year-Quad-Wk : FOLDER.52 Weeks Ending Dec... (2 Replies)
Discussion started by: kanthrajgowda
2 Replies

7. Shell Programming and Scripting

search file and print results with shell script

input file 1.<CRMSUB:MSIN=0100004735,BSNBC=TELEPHON-9814060328-TS11&TS21&TS22,NDC=9814,MSCAT=ORDINSUB,SUBRES=ALLPLMN-SPICE,BAOC=OIC,BAPRC=INFO,ACCSUB=BSS,NUMTYP=MULTI;... (3 Replies)
Discussion started by: dodasajan
3 Replies

8. Shell Programming and Scripting

how can i print the output of the shell script in bigger size

how can i print the output of the shell script in bigger size eg: echo " hello world" i want to print this in the output with bigger size in the middle of the screen. can someone please help me out in that (2 Replies)
Discussion started by: mail2sant
2 Replies

9. Shell Programming and Scripting

search for the contents in many file and print that file using shell script

hello have a file1 H87I Y788O T347U J23U and file2 J23U U887Y I99U T556U file3 I99O J99T F557J file4 N99I T666U R55Y file5 H87I T347U file6 H77U R556Y E44T file7 Y788O K98U H8I May be using script we can use file1 to search for all the files and have the output H87I file5... (3 Replies)
Discussion started by: cdfd123
3 Replies

10. Shell Programming and Scripting

using awk to search and print output

suppose i have one file file A 18 24 30 35 38 45 55 Another file file B 08_46 A 16 V -0.36 0.23 E : 1.41 08_46 A 17 D -1.04 0.22 E : 0.84 08_46 A 18 Q -0.49 0.12 E : 0.06 08_46 A 19 G 0.50 0.14 E : 0.05 08_46 A 20 V ... (5 Replies)
Discussion started by: cdfd123
5 Replies
Login or Register to Ask a Question