I have a slightly different question, but it's related to tomte's original question.
I need to do a find on a filename, then extract the path only, not the filename, from the results of the find. So, I would do a find on, say, passwd. The results are /usr/bin/passwd, /etc/passwd, and /etc/security/passwd. I want to get just /usr/bin, /etc, and /etc/security.
Thanks to all who helped. I have a working extraction now, but I have an interesting situation. I have extracted the string to a variable NAME
I then want to append some string information to the string.
$NAME echos to the appropriate string ABCD
I am in a ksh script and I am using the syntax of
NAME=$NAMEyz
What I end up with is xyCD
I have tried NAME=$NAME'xy'
I have tried NAME="$NAMExy"
and any other variation of this and end up with the same results. Any suggestions?
Actually, I have found that there is a ^M at the end of my string that is causing this to happen, but I cannot seem to sed out the character, anyone have a idea. I have tried sed 's/.^M//g' but it does not seem to take care of the issue.
A lot of times, if you have an extra ^M at the end of your lines, it's because the file either came from a Windows/MSDOS machine, or was edited by a Windows/MSDOS editor (i.e. Notepad via SAMBA). The end of line character for Windows/MSDOS text files is a CR/LF pair, not just the LF that *nix uses. That extra CR is your ^M at the end of the line.
If this is the case, look for a utility called [tt]dos2unix[/tt]. It's purpose is to scrape those ^Ms off.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.