i'm a self-learning new UNIX user
i'm writing my 3rd UNIX script in my life...
but i found myself fall into syndex errors...
this script is use for seperate file from a ftp server...
i need to cut it small into 1000 lines each
with keeping the first and last line of the original file in each new file
All the Files in xyz12345.txt with cuts into xyz2345a.txt , xyz2345b.txt ...etc
the line number will be rearranged from 001,...999.
hope ano can point out my mistakes and my misunderstanding. BIG THANKS
First of all the "split" command could do this for you. But here are a few of your errors...
nline=wc -l $filename
You need backticks or use $(nline=$wc -l $filename)
headLine= `head -1 $filename`
No space bewteen the equal sign and the backtick.
endCode= `abcdefghijklmnopqrstuvwxyz`
Use forward quotes unless you really have a program called abcdefghijklmnopqrstuvwxyz that you want to run. And again lose that space after the equal sign.
if [$nline -gt 1000]
That needs to be "if [ $nline -gt 1000 ]" You must have white space before and after [ and ] so that the shell sees them as a word.
echo $tailLine >> newFileName
newFileName is a variable. If you want the contents of a variable, you must use a dollar sign in front of it.
It looks like you should be incrementing $countLine. And your
nline=`wc -l $filename`
(I added the backquotes) will return both the count and the filename. To get just the count, do:
nline=`cat $filename | wc -l`
You are cutting the first 3 characters of the original line. If this is the original sequence, when it exceeds 999 then you will need logic to cut more than just 3 characters.
If it were not for your requirement to insert a newly generated sequence at front of each line, each loop could grab next set of 999 lines at once with
tail +$startpoint $filename | head -999 >> $newFileName
As is, for each 1000 lines processed, you will be opening and reading one input file 1000 times, and opening and appending to an output file 1000 times. And creation of lots of processes, times 1000.
That's very heavy. An awk script could do what you want with ease and efficiency.
i use the split command to split a one terabyte backup file into 10 chunks of 100 GB each. The files are split one after the other. While the files is being split, I will like to scp the files one after the other as soon as the previous one completes, from server A to Server B. Then on server B ,... (2 Replies)
Hii,
Could someone help me to append string to the starting of all the filenames inside a directory but it should exclude .zip files and subdirectories.
Eg.
file1: test1.log
file2: test2.log
file3 test.zip
After running the script
file1: string_test1.log
file2: string_test2.log
file3:... (4 Replies)
I need a script file for backup (zip or tar or gz) of old log files in our unix server (causing the space problem). Could you please help me to create the zip or gz files for each log files in current directory and sub-directories also?
I found one command which is to create gz file for the... (4 Replies)
Hi,
I am new to shell scripting.Please help me on this.I am using solaris 10 OS and shell i am using is
# echo $0
-sh
My requirement is i have source file say makefile.I need to extract files with extensions (.c |.cxx |.h |.hxx |.sc) from the makefile.after doing so i need to check whether... (13 Replies)
Hi,
Could someone please assist on a quick way of How to extract data from indexed files (ISAM files) maintained in an UNIX(AIX) server.The file data needs to be extracted in flat text file or CSV or excel format .
Usually we have programs in microfocus COBOL to extract data, but would like... (2 Replies)
Hi I am going to migrate our datawarehouse system from HP Tru 64 Unix to the Red Hat Linux.
Inside the box, it is running around 40 cron jobs; inside each cron job, it is calling other shell script files, and the shell script files may again call other shell script files or ctl files(for... (1 Reply)
I have two files one (numbers file)contains the numbers(approximately 30000) and the other file(record file) contains the records(approximately 40000)which may or may not contain the numbers from that file.
I want to seperate the records which has the field 1=(any of the number from numbers... (15 Replies)
Hi,
Our issue is that we want to separate a string of characters, like
xyxyxyxxxxyyxyxy
into a column,
x
y
x
y
...
I'm sure there's an easy awk fix for this, but being inexperienced, I figured I would ask on here.
Thanks a lot in advance! (4 Replies)
The line is like this
+abc+def+mgh+ddsdsd+sa
i.e. words seperated by +. There is a plus in the beginning.
i want to conver this line to
abc, def, mgh, ddsdsd, sa
please provide the logic in the form of a shell script
Thanks in advance (3 Replies)