0
echo "========= CHECKING Current Allocated Workspaces ========="
echo ""
echo "Allocated:"
grep $1 /etc/auto.indirect 
echo ""
echo "Windows Friendly Path:"
IFS=/ read -a frags < <(grep $1 /etc/auto.indirect) #set path components into array frags
frags[0]="${frags[0]%:}" #strip ":" off *-filer-ns
echo "$(IFS=\\ ;printf '\\\\%s' "${frags[*]}" ;)" #set IFS to \ to print frags \-separated

The following I have managed to format to :

========= CHECKING Current Allocated Workspaces =========

Allocated:

wsone-rtp    -rw,hard,intr,quota    filer-filer-ns:/workspace/wslocal010/user

Windows Friendly Path:

\\\wsone-rtp    -rw,hard,intr,quota    filer-filer-ns\workspace\wslocal010\user

I am trying to find a way to remove the trailing information that comes from the table that I am calling.

What i wish to remove from anything called:

wsone-rtp    -rw,hard,intr,quota 

keeping in mind that the first entry of the wsone-rtp changes depending on the earlier user call from the table. For example user A could be : wsone-rtp -rw,hard,intr,quota For example user B could be : wstwo-rtp -rw,hard,intr,quota

I'm thinking there must be some way to remove x number of characters from the beginning of the called string?

Ideal final output would to convert :

wsone-rtp -rw,hard,intr,quota filer-filer-ns:/workspace/wslocal010/user

to

\\filer-filer-ns\workspace\wslocal010\user

  • Welcome to StackOverflow. Can you please try to formulate your question more clearly? What are you trying to do? What is the expected outcome vs. the outcome? Also please try to use a more descriptive title. – Zulan Mar 06 '16 at 20:56
  • Possible duplicate of [What is a unix command for deleting the first N characters of a line?](http://stackoverflow.com/questions/971879/what-is-a-unix-command-for-deleting-the-first-n-characters-of-a-line) – Dunatotatos Mar 06 '16 at 21:01

2 Answers2

1

To remove the X first characters of a string, you can use cut. For example :

echo "a long string" | cut -c 5-
g string
jbr
  • 6,198
  • 3
  • 30
  • 42
Dunatotatos
  • 1,706
  • 15
  • 25
  • you know, I never thought of using cut.. i just changed from IFS=/ read -a frags < <(grep $1 /etc/auto.indirect) #set path components into array frags to IFS=/ read -a frags < <(grep $1 /etc/auto.indirect | cut -c 42-) #set path components into array frags worked like a charm – user2237964 Mar 06 '16 at 21:11
  • I did find as peter suggests below, that some of the table entries that i am grepping are of different leading lengths so | to cut did not always work unfortunately – user2237964 Mar 06 '16 at 21:49
0

I'm still not quite sure what exactly you want to do; but removing exactly n characters from the start of each line sounds brittle. What if some of the options you want to cut away change (isn't is just a coincidence that wsone and wstwo have the same number of characters. Could there be a wsthree?).

If you want to print the last "word", provided the paths do not contain spaces, you could pipe through sed -r 's/.*[ ]+// (find the longest sequence ending in whitespace and replace it with nothing; the square brackets have a spave and a tab in them). With spaces you must rely on a marker: Does the string always start with filer-filer? Then you could say 's/\(.*\)filer-filer/filer-filer/' (find the string ending with "filer'filer" and replace it with just "filer-filer", which you want to keep).

Peter - Reinstate Monica
  • 15,048
  • 4
  • 37
  • 62
  • Thanks Peter, your point is very valid , as i just found out. the formatting of the information I am pulling is infact of different lengths at times. so I do need to try what you have suggested ... there are some difference in the filer names so the filer-filer method may not work in this case. i am trying your sed suggestion now – user2237964 Mar 06 '16 at 21:47
  • on my few tests so far , the sed -r 's/.*[ ]+//' has so far seemed to work without having to worry about losing some characters depending on the source information beginning length . Thanks – user2237964 Mar 06 '16 at 21:52