UNIX shell scripting programming in files

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions UNIX shell scripting programming in files
# 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 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