UNIX shell scripting programming in files

Login to Reply

 
Thread Tools Search this Thread
# 8  
Old 08-24-2017
Quote:
Originally Posted by MadeInGermany
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
# 9  
Old 08-24-2017
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.
# 10  
Old 08-24-2017
Quote:
Originally Posted by mounica bijjala
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
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.
# 12  
Old 08-25-2017
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.
Login to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Similar Threads 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 04:28 AM
Unix Shell Scripting : Comparision of two files CFA UNIX and Linux Applications 12 09-10-2012 09:03 AM
shell programming and scripting kullu Shell Programming and Scripting 2 07-17-2012 04:21 AM
shell programming and scripting harjinder Shell Programming and Scripting 5 03-22-2011 04:31 AM
shell scripting and programming harjinder Shell Programming and Scripting 3 02-02-2011 07:43 AM
Shell Programming and Scripting afredri Shell Programming and Scripting 3 08-13-2010 04:08 PM
Shell Programming and Scripting lemseffert Infrastructure Monitoring 11 10-22-2009 07:26 PM
UNIX Shell Scripting / Programming indiansoil Shell Programming and Scripting 2 07-06-2008 05:05 PM
Shell Programming and Scripting nivas Shell Programming and Scripting 20 02-27-2008 06:36 AM
Shell Programming and Scripting nivas Shell Programming and Scripting 21 02-25-2008 06:27 AM
Shell Programming and Scripting nivas Shell Programming and Scripting 2 02-20-2008 02:59 AM
Shell Programming and Scripting nivas Shell Programming and Scripting 14 02-20-2008 02:07 AM
Shell Programming and Scripting nivas Shell Programming and Scripting 3 02-13-2008 08:10 AM
All times are GMT -4. The time now is 05:17 PM.

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





Not a Forum Member?
Forgot Password?