Sponsored Content
Top Forums Shell Programming and Scripting Calling specific characters from a find variable Post 303029410 by Don Cragun on Friday 25th of January 2019 11:21:47 PM
Old 01-26-2019
Quote:
Originally Posted by scribling
In production we have NDAs. I can't just go posting stuff like that. I'll have to make up similar paths. Yes, even the names of the production are protected.


I still don't understand why you need the sample path. All I need to do is extract the characters from 53:14 and put them into the symlink name. Why is that so hard to understand?
I can do it by setting each shot as a variable but that's a hassle. I figured someone here would know how to do it much easier.

I really don't see what supplying a bunch of big long paths are going to do for anyone. I've already explained where the characters are that I need to extract and pipe in the name.


If I knew more of what you need I'd already know how to do it. I don't. I'm trying.
What supplying a bunch of big long paths with corresponding sample ln commands that you want to produce from those big long paths would do is give us some actual sample data that we could use to make the rest of your inconsistent and confusing requirements make sense. You have shown us examples of strings containing less than 53 characters and you say you want to extract 14 characters from those strings, and then you show us samples where those 14 characters are only 9 characters.

You know exactly what we need. We have asked for it several times and shown you exactly how to produce it. If you couldn't show us the actual data, you could easily have run the requested find command and obfuscated sensitive parts of the generated path (while keeping the same number of characters) and showing us the ln commands with identical obfuscations.

Instead you tell us we are frustrating you by not being able to guess at what you want from the inconsistent samples you have shown us.

I will make one last attempt based on nezabudka's earlier suggestions. With no sample data to work from, I have absolutely no confidence that this even some close to what you want. Try using it at your own peril:
Code:
find . -type d -name 'blablabla' | while read -r path
do	ln -s "$path" "${path:53:14} blablabla"
done

and be warned that creating directory names that contain <space>s (whether actual directories or symbolic links pointing to directories) frequently leads to broken shell scripts falling far short of their intended goal. Nonetheless, a <space> has been included in the symbolic link names this script produces as you seem to require.

Last edited by Don Cragun; 01-26-2019 at 12:26 AM.. Reason: Fix typo: s/falling fall/falling far/
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

calling a aliased variable

Issue: i have variable A which is an alias for variable B which is equal to "THIS IS A TEST" when every i echo variable A i only get the alias name for variable B, NOT the contents of variable B. HOSTNAME# echo $TESTIT + echo THIS IS A TEST THIS IS A TEST HOSTNAME# ls -l total... (10 Replies)
Discussion started by: Optimus_P
10 Replies

2. Shell Programming and Scripting

Find and replace a string a specific value in specific location in AIX

Hi, I have following samp.txt file in unix. samp.txt 01Roy2D3M000000 02Rad2D3M222222 . . . . 10Mik0A2M343443 Desired Output 01Roy2A3M000000 02Rad2A3M222222 . . (5 Replies)
Discussion started by: techmoris
5 Replies

3. Shell Programming and Scripting

sed replacing specific characters and control characters by escaping

sed -e "s// /g" old.txt > new.txt While I do know some control characters need to be escaped, can normal characters also be escaped and still work the same way? Basically I do not know all control characters that have a special meaning, for example, ?, ., % have a meaning and have to be escaped... (11 Replies)
Discussion started by: ijustneeda
11 Replies

4. Shell Programming and Scripting

Can't figure out how to find specific characters in specific columns

I am trying to find a specific set of characters in a long file. I only want to find the characters in column 265 for 4 bytes. Is there a search for that? I tried cut but couldn't get it to work. Ex. I want to find '9999' in column 265 for 4 bytes. If it is in there, I want it to print... (12 Replies)
Discussion started by: Drenhead
12 Replies

5. Shell Programming and Scripting

Count specific characters at specific column positions

Hi all, I need help. I have an input text file (input.txt) like this: 21 GTGCAACACCGTCTTGAGAGG 50 21 GACCGAGACAGAATGAAAATC 73 21 CGGGTCTGTAGTAGCAAACGC 108 21 CGAAAAATGAACCCCTTTATC 220 21 CGTGATCCTGTTGAAGGGTCG 259 Now I need to count A/T/G/C numbers at each character location in column... (2 Replies)
Discussion started by: thienxho
2 Replies

6. Shell Programming and Scripting

Calling a Variable based on a Variable

Hi all, I have a source config file with variables like so: eth1_ip=192.168.1.99 eth2_ip=192.168.1.123 eth3_ip=172.16.1.1 I am trying to run a script which loops based on the number of eth interfaces on a machine and therefore modifies the variable it calls in the environment based on the... (5 Replies)
Discussion started by: landossa
5 Replies

7. Shell Programming and Scripting

Regex in sed to find specific pattern and assign to variable

(5 Replies)
Discussion started by: radioactive9
5 Replies

8. Shell Programming and Scripting

Find and replace with 0 for characters in a specific position

Need command for position based replace: I need a command to replace with 0 for characters in the positions 11 to 20 to all the lines starts with 6 in a file. For example the file ABC.txt has: abcdefghijklmnopqrstuvwxyz 6abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz... (4 Replies)
Discussion started by: thangabalu
4 Replies

9. Shell Programming and Scripting

Calling a variable of variable from a file

Hi All, I have file which have looks like below abc=${def} def=${efg} efg= "this is the actual value" based on "abc" value I have to call "efg" value , Am using below lines but it is not working #!/bin/bash source file.txt echo $abc Please wrap all code, files, input &... (5 Replies)
Discussion started by: Prashanth.K
5 Replies

10. UNIX for Beginners Questions & Answers

Find records with specific characters in 2 nd field

Hi , I have a requirement to read a file ( 5 fields , ~ delimited) and find the records which contain anything other than Alphabets, Numbers , comma ,space and dot . ie a-z and A-Z and 0-9 and . and " " and , in 2nd field. Once I do that i would want the result to have field1|<flag> flag can... (2 Replies)
Discussion started by: ashwin3086
2 Replies
SYMLINK(2)						     Linux Programmer's Manual							SYMLINK(2)

NAME
symlink - make a new name for a file SYNOPSIS
#include <unistd.h> int symlink(const char *oldpath, const char *newpath); DESCRIPTION
symlink creates a symbolic link named newpath which contains the string oldpath. Symbolic links are interpreted at run-time as if the contents of the link had been substituted into the path being followed to find a file or directory. Symbolic links may contain .. path components, which (if used at the start of the link) refer to the parent directories of that in which the link resides. A symbolic link (also known as a soft link) may point to an existing file or to a nonexistent one; the latter case is known as a dangling link. The permissions of a symbolic link are irrelevant; the ownership is ignored when following the link, but is checked when removal or renam- ing of the link is requested and the link is in a directory with the sticky bit set. If newpath exists it will not be overwritten. RETURN VALUE
On success, zero is returned. On error, -1 is returned, and errno is set appropriately. ERRORS
EPERM The filesystem containing newpath does not support the creation of symbolic links. EFAULT oldpath or newpath points outside your accessible address space. EACCES Write access to the directory containing newpath is not allowed for the process's effective uid, or one of the directories in new- path did not allow search (execute) permission. ENAMETOOLONG oldpath or newpath was too long. ENOENT A directory component in newpath does not exist or is a dangling symbolic link, or oldpath is the empty string. ENOTDIR A component used as a directory in newpath is not, in fact, a directory. ENOMEM Insufficient kernel memory was available. EROFS newpath is on a read-only filesystem. EEXIST newpath already exists. ELOOP Too many symbolic links were encountered in resolving newpath. ENOSPC The device containing the file has no room for the new directory entry. EIO An I/O error occurred. NOTES
No checking of oldpath is done. Deleting the name referred to by a symlink will actually delete the file (unless it also has other hard links). If this behaviour is not desired, use link. CONFORMING TO
SVr4, SVID, POSIX, BSD 4.3. SVr4 documents additional error codes SVr4, SVID, BSD 4.3, X/OPEN. SVr4 documents additional error codes EDQUOT and ENOSYS. See open(2) re multiple files with the same name, and NFS. SEE ALSO
readlink(2), link(2), unlink(2), rename(2), open(2), lstat(2), ln(1) Linux 2.0.30 1997-08-21 SYMLINK(2)
All times are GMT -4. The time now is 11:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy