Homework & Coursework Questions

Students must use and complete the template provided. If you do not use the template your post may be deleted! Special homework rules apply here.

UNIX shell scripting programming in files

👤 Login to reply

 
Thread Tools Search this Thread Display Modes
    #8  
Old 08-24-2017
mounica bijjala mounica bijjala is offline
Registered User
 
Join Date: Aug 2017
Last Activity: 24 August 2017, 12:06 PM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by MadeInGermany View Post
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)
---------- Post updated at 10:23 AM ---------- Previous update was at 10:21 AM ----------

I created dir2 is the sub directory of dir1
My current working directory is home/dir1/dir2
Sponsored Links
    #9  
Old 08-24-2017
MadeInGermany MadeInGermany is offline Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 19 July 2018, 2:35 AM EDT
Location: Simplicity
Posts: 4,156
Thanks: 365
Thanked 1,419 Times in 1,275 Posts
Assuming your current work directory is dir2 being a subdirectory of dir1, you can refer to dir1 as ...
Assuming you have file1 in dir1, you can refer to it as ../file1.
Assuming you have file2 in dir2 that is your current work directory you can refer to it as ./file2 or simply file2.
Sponsored Links
    #10  
Old 08-24-2017
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Last Activity: 3 July 2018, 11:43 PM EDT
Location: In the leftmost byte of /dev/kmem
Posts: 5,786
Thanks: 112
Thanked 1,698 Times in 1,248 Posts
Quote:
Originally Posted by mounica bijjala View Post
Code:
grep -f file1 file2

So far, so good. Notice, though, that every file has a "short address" (the files name) and a "long address" (the fies name and its full path).

This works similar to telephone numbers: if you give someone your number without a regional area code and country code it will work as long as the person is in the same area as you.
Code:
123 456 789

But once outside this area you need to give him your area code too to make it work
Code:
0123 / 123 456 789

and to make sure the number works from whereever he is you will have to add the country code too:

Code:
+123 (123)  123 456 789

The same is true for files: you can address them by their name only, but then you will only find them if you happen to be in the same directory. If you aren't you won't. To make sure you find them regardless of where you are provide a full pathname instead. In this case the files name is not
Code:
file1

but rather
Code:
/some/directory/where/to/find/file1

As a general rule: to make sure files are always found regardless of from where you call a script use always the long form of (so-called) "absolute path names" when you address files inside scripts.

I hope this helps.

bakunin
    #11  
Old 08-24-2017
MadeInGermany MadeInGermany is offline Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 19 July 2018, 2:35 AM EDT
Location: Simplicity
Posts: 4,156
Thanks: 365
Thanked 1,419 Times in 1,275 Posts
One word to the -r (recurse) options for diff or grep: they can only work if the directories are next to each other, and the strength is if the number of files is unknown. Not the case here, we have two known files.
Sponsored Links
    #12  
Old 08-25-2017
MadeInGermany MadeInGermany is offline Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 19 July 2018, 2:35 AM EDT
Location: Simplicity
Posts: 4,156
Thanks: 365
Thanked 1,419 Times in 1,275 Posts
How do the two input files look like?
Is there one word per line or many words per line?
It's much easier to work on full lines than on parts of the lines.
Sponsored Links
👤 Login to reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell script to read lines in a text file and filter user data Shell Programming and Scripting VikrantD UNIX for Dummies Questions & Answers 3 03-25-2014 03:28 AM
Unix Shell Scripting : Comparision of two files CFA UNIX and Linux Applications 12 09-10-2012 08:03 AM
UNIX Shell Scripting / Programming indiansoil Shell Programming and Scripting 2 07-06-2008 04:05 PM



All times are GMT -4. The time now is 03:26 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?