Query in unix


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Query in unix
# 1  
Old 12-25-2007
Query in unix

hi ..
i m in gr8 confusion
for eg
two number of files 1 & 2
1 contains following
a
b
c


2 gives
a
b
d
e

on executing following command
diff 1 2 | grep ">" | sed 's/>//g' >output.dat

in output.dat i get following data
d
e

but my main motive is to compare 2 files line by line and generate output until i come to end of line of file 1
i.e. here 1 has 3 lines n 2 has 4 lines ... it should compare line by line for 3 lines and NOT 4 lines and pick up the modified data from file 2

i want the output to be
d
and NOT
d
e


please help me out ... urgent
thanx a ton Smilie
# 2  
Old 12-25-2007
just to understand the problem:
what if

file1
-------
a
b
c
f
g
h

file2
---------
a
b
d
e
f
h

what should the output be ?

d
e
f

??
# 3  
Old 12-26-2007
yes u r absolutely right it should be
d
e
f
since here both file1 and file1 have same number of rows so row wise comparison is done for each line and if there is any variance the data from file2 has to be picked up from the modified line Smilie
# 4  
Old 12-26-2007
awk one

Code:
awk 'FNR==NR {a[NR]=$0} FNR!=NR {if(a[FNR]!=$0) print a[FNR]}' file2 file1

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Running a SQL Query from UNIX

Hi, Could you please help me on this. I have bulk of queries written in text file. I want to use those queries and want to execute from UNIX. I don't want to run this file as a sql file as this file will change every week. I want to run it in my environment as bulk sql statement from text... (1 Reply)
Discussion started by: abhii
1 Replies

2. UNIX for Dummies Questions & Answers

UNIX Query About wc -l output

I was performing the wc -l operation in one data file the result is less when i was giving -nu on the view of the file. while giving wc -l the count is 5023 after setting line numbers in view of file is giving 5024. Can anyone help on this.... (5 Replies)
Discussion started by: abhii
5 Replies

3. Shell Programming and Scripting

query error in unix

Hi all , am using unix aix and Am getting the syntax error on 'UNION'.. can anybody tell me the solutions.. INSERT INTO table1 ( Type , num_items , num_letters , total_value ) (select type='1', num_items, num_letters=count(*), total_value=sum(letter_value) from table2... (1 Reply)
Discussion started by: Venkatesh1
1 Replies

4. UNIX for Dummies Questions & Answers

Forming a query in unix level

Hi, I will execute a query in sqlplus and redirect to a file. The file will contains the date value such as 2011-04-12 02:00:00. i want to make the content of the file such as, select * from table where col1>to_date('2011-04-12 02:00:00','yyyy-mm-dd HH24:MI:SS'). Apar from the bold... (1 Reply)
Discussion started by: pandeesh
1 Replies

5. Shell Programming and Scripting

SQLPLUS query in Unix script

Hi, I am using sqlplus query to get results in a csv format in unix. I am using ksh, and below is the query. echo "select r.num|| ',' || p.path ||',"' || r.issue_description ||'",' ||p.timestamp from events r, messagepath p;">> $QUERY_FILE sqlplus -s $LOGIN @ $QUERY_FILE>>$OUTFILE ... (2 Replies)
Discussion started by: Nutan
2 Replies

6. Shell Programming and Scripting

Isql query in unix shell

Hi i want write a script for list of sysbase are having access or open. then i wrote like: USER="abc" PASS="xyz" SERVER="SCCS" DB="blue" WORK_DIR="/usr/home/ramakrishna" set -x isql -U${USER} -P${PASS} -S${SERVER}<<EOF>$WORK_DIR/output.log go use blue (database name) go use... (0 Replies)
Discussion started by: koti_rama
0 Replies

7. Shell Programming and Scripting

issue with the query output in unix

I am running a query with contains blank spaces in between in the output. But when I open and read the file in UNIX i am not able to cursor the balnk spaces instead it is moving like tabs. Please help suppose my query - Select ' '||text from tab1; the cursor should move to 1st and... (1 Reply)
Discussion started by: sbmk_design
1 Replies

8. Shell Programming and Scripting

General UNIX Query

Hi all, I am having putty in my system.But I dont have access to any UNIX Servers.Is there any default or common UNIX Server so that anyone can access and be familiar with UNIX and Shell scripting. I want to work and practice in UNIX..Thats why I am asking this question. Kindly give me... (2 Replies)
Discussion started by: dave_nithis
2 Replies

9. UNIX for Dummies Questions & Answers

Query in Unix

hello folks i was executing few shell scripts using another login id , those were working fine ,these shell scripts basically call oracle stored procs now when i copied those shell scripts files to another user location n logged into that user's unix id , it is showing errors ...:( the oracle... (3 Replies)
Discussion started by: Dana Evans
3 Replies

10. UNIX for Advanced & Expert Users

Unix Date query

Hi there, I am trying to do the following in Unix (Solaris 2.7): 1...Find the actual date 7 days ago in format (dd-mmm-yyyy) and with the weekday prefably, 2...Find the date 5 days after the above in the same format. How can I do this in Unix instead of accessing our Oracle database and... (5 Replies)
Discussion started by: csong2
5 Replies
Login or Register to Ask a Question