Sponsored Content
Top Forums Shell Programming and Scripting Script for linking files with paths in 2 text files Post 302891532 by Scrutinizer on Thursday 6th of March 2014 09:25:20 AM
Old 03-06-2014
@LeftoverStew, tt is a bit more complicated than that. A link in the same directory, means making the link to the file name only (without the path). Also, there are all sorts of error condition that might occur. Also since the match is made line for line by the content of the files, they need to be read at the same time.

For example:

Code:
complain() {
  printf "%s\n" "$*"
  continue
}

while read file && read link<&3
do
  # determine directories
  dir_file=${file%/*}
  dir_link=${link%/*}

  # determine name of new link
  new_link=${link%.*.*}_done.${link#*.}

  # determine name the local link should point to
  local_file=${file##*/}
  
  # complain if there are things wrong
  [ -e "$file" ]                || complain "file $file does not exist"
  [ "$dir_file" = "$dir_link" ] || complain "The directories of $file and $link are not the same, so a local symlink cannot be made"
  [ ! -e "$new_link" ]          || complain "An entry for $new_link already exists"

  # create the link
  ln -s "$local_file" "$new_link"
done < 1.txt 3<2.txt


Last edited by Scrutinizer; 03-06-2014 at 11:10 AM..
These 3 Users Gave Thanks to Scrutinizer For This Post:
 

10 More Discussions You Might Find Interesting

1. Programming

compiling and linking 2 C files ...??

Hi mates, I am trying to copile and link to C programs with command: cc file1,file2 but i raises the error "file not found" ... am i doing the right way? any suggestion will be appreciated. thanks abdul (4 Replies)
Discussion started by: abdul
4 Replies

2. UNIX for Dummies Questions & Answers

modifying C file and linking back to project files

hi, This is the first time I work in a big C project. All source code files are located in say directory /source/pp and all header files are in /include/pp. I've created a link to both of these directories from my home dir, say /home/ss. So in the /home/ss dir I have the /source/pp and /include/pp... (1 Reply)
Discussion started by: bruins2005
1 Replies

3. UNIX for Dummies Questions & Answers

Linking Files in UNIX (shortcuts)

Hello, Can anyone tell me how I can make a file link or shortcut in UNIX 4.0, several file links where damaged during an outage examples below. Examples: file -> file libX11.so -> /usr/shlib/libX11.so.pre.O3D All of the file links that were damaged were in /shlib and point to... (3 Replies)
Discussion started by: jays337
3 Replies

4. Programming

C files searching and Linking

Dear friends, First off all , let me apologize for my inexperience. I am just starting use of Linux and gcc . Actually I ve some .c files in the present directory , and now I am giving +vc <my_file1.c> <my.file2.c> <myfile3.c>. All the c files are in present directory.... (2 Replies)
Discussion started by: user_prady
2 Replies

5. UNIX Desktop Questions & Answers

how to display paths of files in a directory

hi guys does anyone know how to display the file paths of the files stored within a directory at the command terminal? e.g. if i have a directory called "home", how do i display the file paths of the files inside the directory? cheers (2 Replies)
Discussion started by: Villaman69
2 Replies

6. Shell Programming and Scripting

Find text containing paths and replace with a string in all the python files

I have 100+ python files in a single directory. I need to replace a specific path occurrence with a variable name. Following are the find and the replace strings: Findstring--"projects\\Debugger\\debugger_dp8051_01\\debugger_dp8051_01.cywrk" Replacestring--self.projpath I tried... (5 Replies)
Discussion started by: noorsam
5 Replies

7. Shell Programming and Scripting

how to write a script for existing of IP_add in the files under paticular paths.

Hello , I want to write a script to test the IP_add is hardcoded in the paticular files. the files are available in path . for example. /abs/abn/jkg/frames.sh. like this some files are there in the same path.I manually replaced the IP_ADD with domain name in required files.now i have to... (1 Reply)
Discussion started by: rajkumar_g
1 Replies

8. Shell Programming and Scripting

Script to delete files older than x days and also taking an input for multiple paths

Hi , I am a newbie!!! I want to develop a script for deleting files older than x days from multiple paths. Now I could reach upto this piece of code which deletes files older than x days from a particular path. How do I enhance it to have an input from a .txt file or a .dat file? For eg:... (12 Replies)
Discussion started by: jhilmil
12 Replies

9. Shell Programming and Scripting

Search and compare files from two paths

Hi All, I have a 2 path, one with oldfile path in which has several sub folders,each sub folders contains a config file(basically text file), likewise there will be another newfile path which will have sub folders, each sub folders contains a config file. Need to read files from oldfile... (6 Replies)
Discussion started by: Optimus81
6 Replies

10. Programming

Linker errors linking to .a files on OS X

Basically my problem is that when I try to compile anything using ./configure && make, it fails because of linker errors. I can reproduce the behavior I'm getting as follows: I have the two following files main.c: #include <stdio.h> extern void func(void); int main(int argc, char... (5 Replies)
Discussion started by: MarshallBanana
5 Replies
SYMLINK(2)							System Calls Manual							SYMLINK(2)

NAME
symlink - make symbolic link to a file SYNOPSIS
symlink(name1, name2) char *name1, *name2; DESCRIPTION
A symbolic link name2 is created to name1 (name2 is the name of the file created, name1 is the string used in creating the symbolic link). Either name may be an arbitrary path name; the files need not be on the same file system. RETURN VALUE
Upon successful completion, a zero value is returned. If an error occurs, the error code is stored in errno and a -1 value is returned. ERRORS
The symbolic link is made unless on or more of the following are true: [ENOTDIR] A component of the name2 prefix is not a directory. [EINVAL] Either name1 or name2 contains a character with the high-order bit set. [ENAMETOOLONG] A component of either pathname exceeded 255 characters, or the entire length of either path name exceeded 1023 characters. [ENOENT] The named file does not exist. [EACCES] A component of the name2 path prefix denies search permission. [ELOOP] Too many symbolic links were encountered in translating the pathname. [EEXIST] Name2 already exists. [EIO] An I/O error occurred while making the directory entry for name2, or allocating the inode for name2, or writing out the link contents of name2. [EROFS] The file name2 would reside on a read-only file system. [ENOSPC] The directory in which the entry for the new symbolic link is being placed cannot be extended because there is no space left on the file system containing the directory. [ENOSPC] The new symbolic link cannot be created because there there is no space left on the file system that will contain the sym- bolic link. [ENOSPC] There are no free inodes on the file system on which the symbolic link is being created. [EDQUOT] The directory in which the entry for the new symbolic link is being placed cannot be extended because the user's quota of disk blocks on the file system containing the directory has been exhausted. [EDQUOT] The new symbolic link cannot be created because the user's quota of disk blocks on the file system that will contain the symbolic link has been exhausted. [EDQUOT] The user's quota of inodes on the file system on which the symbolic link is being created has been exhausted. [EIO] An I/O error occurred while making the directory entry or allocating the inode. [EFAULT] Name1 or name2 points outside the process's allocated address space. SEE ALSO
link(2), ln(1), unlink(2) 4.2 Berkeley Distribution August 26, 1985 SYMLINK(2)
All times are GMT -4. The time now is 02:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy