08-20-2009
Thank you so much Smiling Dragon!
I finally got a chance to try this.
I just realized that I made a mistake in the question I originally asked.
This code you suggested:
for file in xx*; do mv "$file" `head -1 "$file" | cut -d '|' -f 2`.txt; done
works perfectly for what I asked for, but I just noticed that my files are actually in the format:
asdf...asdf | some Junk | asdf...asdf |name1| asdf... .... and no more vertical bars
I was actually supposed to name the files after what is between the SECOND set of vertical bars, rather than the first.
Is there a way to do that ??
And by any chance, now that I've renamed 500 files incorrectly, is there an undo button in unix
??
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I have an excel file with more than 65K records... Since excel does not take more than 65K records i wan to split the file and send it as two excel files... Could some help me how to use the csplit by specifiying the no of records (7 Replies)
Discussion started by: savitha
7 Replies
2. Windows & DOS: Issues & Discussions
Hey folks,
I have used gVim in Windows for many years but I have never found an answer to a very simple question I am going to ask you guys...
My question is if there is a way to eliminate the creation of those ~ files that gVim creates in Windows. If you have ever used gVim in Windows you... (2 Replies)
Discussion started by: ghbarratt
2 Replies
3. UNIX for Dummies Questions & Answers
Hi,
I've searched and read, and searched and read some more; but I'm still not connecting the dots or understanding what I need to change.
I have a script that creates a file. If I run it as root, the file gets created with 644 permissions like I want. That seems to make sense (at least I... (2 Replies)
Discussion started by: 65bit
2 Replies
4. Shell Programming and Scripting
for every specific $1,$2 check the values ($2,$3) of their E ot I of input1 and overlap with input2.
Specify names based on output.
#######
if middle value is missing name them "SE"
if first value is missing name them "AFE"
if last value is missing name them "ALE"
if 2 middle values are... (1 Reply)
Discussion started by: ruby_sgp
1 Replies
5. Shell Programming and Scripting
Hi ,
i have below files in wrk folder. file names are
1102090001.CLT
1102090003.CLT
1102100019.CLT
1102100020.CLT
the above files are concatenate to one file but that concatenate file name must be same naming convention. (date +%y%m%d)and 0001 count.
example : concatenate file... (9 Replies)
Discussion started by: krbala1985
9 Replies
6. UNIX for Dummies Questions & Answers
I have a whole directory and I need each lines of each file to be separated to a new file but I am facing problem naming them :(
some of the files even might be empty
the output files should be names original file name + the number of the line or any incremental number
FILES="data/*"
for X in... (12 Replies)
Discussion started by: A-V
12 Replies
7. UNIX Desktop Questions & Answers
Greetings Unix exports,
I am facing some problems in combining files with different name patterns with a directory and I would appreciate if you can help me
I have more than 1000 files but they follow a specific pattern of naming. e.g. 64Xtest01.txt
They are divided into two sets of test and... (9 Replies)
Discussion started by: A-V
9 Replies
8. UNIX for Advanced & Expert Users
In our project we have several unix scripts that trigger different processes. These scripts write logs to a particular folder 'sesslogs', create output data files in a separate directory called 'datafiles' etc. Usually L1 support team re-run these scripts . We donot want L1 support team to have... (14 Replies)
Discussion started by: waavman
14 Replies
9. Shell Programming and Scripting
Since my last threads were closed on account of spamming, keeping just this one opened!
Hi,
I have the following reports that get generated every 1 hour and this is my requirement:
1. 5 reports get generated every hour with the names
"Report.Dddmmyy.Thhmiss.CTLR"... (5 Replies)
Discussion started by: Jesshelle David
5 Replies
10. Shell Programming and Scripting
I want to crop an image and am using convert
convert mountain.png -crop 3000x4500 +repage -format png mountain--cr.png
The problem is that convert is creating 4 files
mountain--cr-0.png
mountain--cr-1.png
mountain--cr-2.png
mountain--cr-3.png
The first is what I need, the other... (10 Replies)
Discussion started by: Kangol
10 Replies
csplit(1) General Commands Manual csplit(1)
NAME
csplit - context split
SYNOPSIS
prefix] number] file arg1 [...argn]
DESCRIPTION
reads file, separates it into n+1 sections as defined by the arguments arg1 ... argn, and places the results in separate files. The maxi-
mum number of arguments (arg1 through argn) allowed is 99 unless the option is used to allow for more output file names. If the option is
specified, the resulting filenames are through prefixNN where NN is the two-digit value of n using a leading zero if n is less than 10. If
the option is not specified, the default filenames through are used. file is divided as follows:
Default Prefixed
Filename Filename Contents
-----------------------------------------------------
xx00 prefix00 From start of file up to (but
not including) the line refer-
enced by arg1.
xx01 prefix01 From the line referenced by
arg1 up to the line referenced
by arg2.
.
.
.
xxNN prefixNN From the line referenced by
argn to end of file.
If the file argument is standard input is used.
supports the Basic Regular Expression syntax (see regexp(5)).
Options
recognizes the following options:
Suppress printing of all character counts
normally prints the character counts for each file created).
Leave previously created files intact
normally removes created files if an error occurs).
Name created files
through prefixNN (default is through
The output file name suffix will use
number digits instead of the default This allows creation of more than 100 output files.
Arguments (arg1 through argn) to can be any combination of the following:
Create a file containing the section from the current line
up to (but not including) the line matching the regular expression regexp. The new current line becomes the line
matching regexp.
Create a file containing the section from the current line
up to (but not including) the nth before or after the line matching the regular expression regexp. (e.g., The new
current line becomes the line matching plus or minus n lines.
equivalent to except that no file is created for the section.
line_number Create a file from the current line up to (but not including) line_number. The new current line becomes line_number.
Repeat argument.
This argument can follow any of the above argument forms. If it follows a regexp argument, that argument is applied
num more times. If it follows line_number, the file is split every line_number lines for num times from that point
until end-of-file is reached or num expires.
Repeats previous operand as many times as necessary to
finish input.
Enclose in appropriate quotes all regexp arguments containing blanks or other characters meaningful to the shell. Regular expressions must
not contain embedded new-lines. does not alter or remove the original file; it is the user's responsibility to remove it when appropriate.
EXTERNAL INFLUENCES
Environment Variables
determines the collating sequence used in evaluating regular expressions.
determines the characters matched by character class expressions in regular expressions.
determines the language in which messages are displayed.
If or or is not specified in the environment or is set to the empty string, the value of is used as a default for each unspecified or empty
variable. If is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of If any internationalization
variable contains an invalid setting, behaves as if all internationalization variables are set to "C". See environ(5).
International Code Set Support
Single- and multi-byte character code sets are supported.
DIAGNOSTICS
Messages are self explanatory except for:
which means that the given argument did not reference a line between the current position and the end of the file. This warning also
occurs if the file is exhausted before the repeat count is.
EXAMPLES
Create four files, through After editing the ``split'' files, recombine them back into the original file, destroying its previous contents.
Perform editing operations
Split a file at every 100 lines, up to 10,000 lines (100 files). The option causes the created files to be retained if there are fewer
than 10,000 lines (an error message is still printed).
Assuming that follows the normal C coding convention of terminating routines with a at the beginning of the line, create a file containing
each separate C routine (up to 21) in
SEE ALSO
sh(1), split(1), environ(5), lang(5), regexp(5).
STANDARDS CONFORMANCE
csplit(1)