UNIX shell scripting programming in files

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions UNIX shell scripting programming in files
# 1  
Old 08-24-2017
UNIX shell scripting programming in files

Create 2 files in unix in 2 different directories, compare them and fetch common words between these 2 files. Print them on the screen and also redirect the output to your home directory in the below format: file 1 | file 2 line no: word 1 | line no: word 1 line no: word 2 | line no: word 2 line no:


Code:
#!/bin/sh
#i have created two files in different directories named dir1 and dir2 at command line. files named as file1 and file2.

mv file1 dir2
grep -f file1 file2 
exit

problem i am not able to move the file and how to get given syntax asked in the question

Last edited by rbatte1; 08-24-2017 at 06:21 AM.. Reason: Correcting CODE tags
# 2  
Old 08-24-2017
Welcome mounica bijjala ,

Firstly thank you for trying to use the CODE tags. The closing tag needs to be [/CODE] though.

Considering your question, I have a few to questions pose in response first:-
  • Is this homework/assignment? There are specific forums for these.
  • What have you tried so far on the bit you are stuck with?
  • What output/errors do you get?
  • What OS and version are you using?
  • What are your preferred tools? (C, shell, perl, awk, etc.)
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)
Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.


We're all here to learn and getting the relevant information will help us all.



Kind regards,
Robin
# 3  
Old 08-24-2017
Yes this is homework.
Please provide school name, professor name, course name/number, as said in the top readme article in this forum!

I guess the required output is multi-line?
Code:
file 1 | file 2
line no: word 1 | line no: word 1 
line no: word 2 | line no: word 2

I have wrapped it in code tags.

Last edited by MadeInGermany; 08-24-2017 at 07:26 AM..
# 4  
Old 08-24-2017
Yes the output is multiline.
I have a basic knowledge in Unix.
I am not able compare the two files present in two different directories.
I know nl is the command to get the line number.But how to compare the files and how to get the output in the required syntax?

---------- Post updated at 06:05 AM ---------- Previous update was at 05:58 AM ----------

I have created 2 directories named dir1 and a subdirectory dir2. First i used a command diff -r ./dir1 dir2
Because it am in dir2 i dint used ./
As i read -r buffer is used to compare recursively the subdirectories.
I am getting an error said dir1 not found.
Then i used grep command and i got the same error.
I have strucked at comparing the files.
# 5  
Old 08-24-2017
First please provide school name, professor name, course name/number, as said in the top readme article in this forum!
# 6  
Old 08-24-2017
i am from amrita college of engineering,
course unix
professor ashwin
# 7  
Old 08-24-2017
The first task is: have two directories.
Did you create dir2 within dir1 or next to dir1?
And where is your current work directoy? (pwd command)
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

2. UNIX and Linux Applications

Unix Shell Scripting : Comparision of two files

Hi, We need to compare a text file File1.txt and config file File2.txt in a way that it checks if the content of File1.txt exists between the range mentioned in File2.cfg. The range here is the range between col1 and col2 of File2.cfg If the content of File1.txt lies between the range of... (12 Replies)
Discussion started by: CFA
12 Replies

3. Shell Programming and Scripting

shell programming and scripting

hi, i am trying this while loop and i only want that it should only read food as pizza....no other entry should be taken here. #!/usr/bin/perl -w $food = " "; while ( $food ne 'pizza' ) { print 'enter what you had last night: '; chomp ($food = <STDIN>); #print $food ; } ... (2 Replies)
Discussion started by: kullu
2 Replies

4. Shell Programming and Scripting

shell programming and scripting

I was trying out some new series to get it print 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 and the seond one is 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 but was unable to get the result. (5 Replies)
Discussion started by: harjinder
5 Replies

5. Infrastructure Monitoring

Shell Programming and Scripting

# set date to your spec: this is month/day/yr/hr/min/sec: sysdate=`date '+%m/%d/%Y-%H:%M:%S'` # get the last line before the history file is modified tail -1 /tmp/hosthistory.txt |while read lastdate mydevices do echo $lastdate echo $mydevices done LIST = 'ypcat hosts|| sort... (11 Replies)
Discussion started by: lemseffert
11 Replies

6. Shell Programming and Scripting

UNIX Shell Scripting / Programming

Hi, I am looking for a PDF or an e-book which can show in details how to do Shell Scripting or Programming. Can anybody provide me with a link to such a tutorial? I have downloaded some tutorials but they show only basics and not give any in-depth study material. I am using Red Hat Linux... (2 Replies)
Discussion started by: indiansoil
2 Replies

7. Shell Programming and Scripting

Shell Programming and Scripting

Hi, Iam having file1 as follows: ERTYUIOU|1234567689089767688 FDHJHKJH|6817738971783893499 JFKDKLLUI|9080986766433498444 FILE2 ERTYUIOU|1234567689089767688 resh@abc_com 767637218328322332 893589893499 asdsddssd ... (21 Replies)
Discussion started by: nivas
21 Replies

8. Shell Programming and Scripting

Shell Programming and Scripting

I want to compare some files. say iam having 2 sets of files ,each is having some 10 files. ie, file1 1a.txt 1b.txt 1c.txt ... file2 2a.txt 2b.txt 2c.txt ... i need to read line by line of this files parralley.. ie.. i want to read file1 first line that is 1a.txt and file2... (2 Replies)
Discussion started by: nivas
2 Replies

9. Shell Programming and Scripting

Shell Programming and Scripting

Hi, iam having the file as follows: ABCDEFGH|0987654321234567 ABCDEFGH|0987654321234523 ABCDEFGH|0987654321234556 ABCDEFGH|0987654321234545 POIUYTRE|1234567890890678 POIUYTRE|1209867757352567 POIUYTRE|5463879088797131 POIUYTRE|5468980091344456 pls provide me the split command ... (14 Replies)
Discussion started by: nivas
14 Replies
Login or Register to Ask a Question