There are several possibilities to achieve this: all these filenames are of the form
<first_part><delimiter><second_part>
and you want to split them at <delimiter>. This chan be achieved by:
1. using shell means
${varname#*<delimiter>} will expand to the part of varname following delimiter
${varname%<delimiter>*} will expand to the part of varname preceeding delimiter
Example: 2. using cut
You can use "cut" to split a string at some "field boundaries" delimited by a delimiter character. Quite commonly this is a blank but this doesn't have to be so. See the manpage for "cut" for details:
This would be the preferential method when you have to split your variable not one but several times. In this case you could split to "field" 3,4,5, etc..
3. using sed/awk
You could use sed or awk to split your variables content into parts. This would be the least preferable method as it would be an overkill for such a problem.
After having split your variables into parts you can use "printf" to print the parts as column headers in a table. "printf" has also a manpage and works almost identical to the standard C function printf().
I want to execute something like this:
find . -type f -regex '$REGEX' -print | xargs split -d -C $SIZE
The problem is that I want the name of the split files to be the same name as original files. So if my directory has two files called abc.txt and def.txt, then I want the split files to be... (1 Reply)
Hi,
I have a question on bash. Basically I would like to print a file name using bash. I am actually trying to grep a particular character in sequential files.
I have alot files such that a.txt, b.txt,c.txt...etc.
If I found a certain character, I would print that particular filename.
I... (5 Replies)
I have a file with data such as:
X Y Z 4 1,3,5,7, 4,6,8,10,
A B C 3 2,3,4, 5,9,11,
E F G 5 1,2,3,4,5, 8,9,10,11,12,
Columns 1, 2 and 3 are descriptions. Column 4 tells how many numbers are in columns 5 and 6
What I'd like to do is split column 5 and column 6 by the "," and then... (3 Replies)
#!/bin/ksh
for files in `ls *.gz`
do
gunzip -c $files | awk -v s=$files -F\" '{print s","$6}'
done
I have tried FILENAME parameter but it did not work please help. (1 Reply)
I'm trying to clean up my samba share and need to print the found file or print the path of the image it tried to searched for. So far I have this but can't seem to get the logic right. Can anyone help point me in the right direction?
for FILE in `cat list`; do
if ;
then
... (1 Reply)
Hello,
I have the string "/a/b/c/ddd.txt" and i want to get only the filename, in this case "ddd.txt". I have as something known in the script the pattern "/a/b/c/", so I`ve tried something like:
echo "/a/b/c/ddd.txt" | cut -d "/a/b/c/" -f2
but it doesn`t go, any help?.
thanks,
bye (2 Replies)
I can got the filename with this script. it's only show "-" in result.
cut -d , -f7 CSV_d.* | awk 'OFS=":"{print FILENAME,substr($1,1,8),substr($1,9,2),substr($1,11,2),substr($1,13,2)}' | sort |uniq (2 Replies)
Hello;
I have a file consists of 4 columns separated by tab. The problem is the third fields. Some of the them are very long but can be split by the vertical bar "|". Also some of them do not contain the string "UniProt", but I could ignore it at this moment, and sort the file afterwards. Here is... (5 Replies)
In PERL script
I have few files named theme1.htm,theme2.htm,theme3.htm and so on.
now I need to write perl code to split the the filename and store only that particular digit.
Example
--------------
filename is theme1.htm
output should be 1
another example
---------------... (5 Replies)
How to print the split array elements in the same line with awk?
echo "1 2 3 4 /path/to/file1" | awk 'split($5, A, "/") {print $0; for (i=1; i<=length(A); i++) print A}'
echo "2 2 3 6 /longer/path/to/another/file2" | awk 'split($5, A, "/") {print $0; for (i=1; i<=length(A); i++) print A}'
What... (6 Replies)
Discussion started by: yifangt
6 Replies
LEARN ABOUT MOJAVE
textutil_split
textutil::split(n) Text and string utilities, macro processing textutil::split(n)
__________________________________________________________________________________________________________________________________________________NAME
textutil::split - Procedures to split texts
SYNOPSIS
package require Tcl 8.2
package require textutil::split ?0.7?
::textutil::split::splitn string ?len?
::textutil::split::splitx string ?regexp?
_________________________________________________________________DESCRIPTION
The package textutil::split provides commands that split strings by size and arbitrary regular expressions.
The complete set of procedures is described below.
::textutil::split::splitn string ?len?
This command splits the given string into chunks of len characters and returns a list containing these chunks. The argument len
defaults to 1 if none is specified. A negative length is not allowed and will cause the command to throw an error. Providing an
empty string as input is allowed, the command will then return an empty list. If the length of the string is not an entire multiple
of the chunk length, then the last chunk in the generated list will be shorter than len.
::textutil::split::splitx string ?regexp?
This command splits the string and return a list. The string is split according to the regular expression regexp instead of a simple
list of chars. Note that if you parentheses are added into the regexp, the parentheses part of separator will be added into the
result list as additional element. If the string is empty the result is the empty list, like for split. If regexp is empty the
string is split at every character, like split does. The regular expression regexp defaults to "[\t \r\n]+".
BUGS, IDEAS, FEEDBACK
This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category textutil
of the Tcllib SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have for
either package and/or documentation.
SEE ALSO
regexp(n), split(n), string(n)
KEYWORDS
regular expression, split, string
CATEGORY
Text processing
textutil 0.7 textutil::split(n)