|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Split the file and access that files through array and loop
Hi All,
the below is my requirement.. i need to split the file based on line and put that files in a array and need to access that files through loop finally i should send the files through mail.. how can we achieve this ..I am new to shell script please guide me.. I am using KSH.. Thanks in advance.. Regards, Kalidoss |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Yes?
And what have you done so far? |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Hi Vbe, I have done the below ... Code:
split -l 2 line_test.txt line_test.txt
set -A TEST_ARRAY line_test.txta*
a=0
for i in ${TEST_ARRAY[@]}
do
echo " TEST_ARRAY[$a] : $i"
mv $i ./line_test_$a.txt
(( a = a + 1 ))
doneit is working ...I have searched and tried this... But I dont know that the above is correct. Is there some nice way to do the same ? Regards, Kalidoss
Last edited by vbe; 01-29-2013 at 08:46 AM.. |
|
#4
|
|||
|
|||
|
Using an array for this is kind of overkill. If you just want to read lines one by one, read lines one by one. Code:
A=0
while read -r LINE
do
echo mv "$LINE" "./line_test_${A}.txt"
let A=A+1
done < inputfileThis ought to work in any Bourne shell, while that array code will only work in KSH. |
| The Following User Says Thank You to Corona688 For This Useful Post: | ||
kalidoss (01-31-2013) | ||
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Hi Corona,
I have tried your code , i got the below error... syntax error at line 6 : `done' unexpected regards, Kalidoss |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Hi Franklin,
Yes. I have saved the file with a windows editor. it is working fine now.. This code reads the file line by line.. I want to split the file.. How can we achieve this .. Please give me any idea.. Thanks in advance.. Regards, Kalidoss |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| problem access array outside of loop in bash | adlmostwanted | Shell Programming and Scripting | 4 | 12-12-2011 11:18 AM |
| Push records to array during implicit loop and write to file | jospan | Shell Programming and Scripting | 0 | 01-12-2010 08:06 AM |
| Not access variable outside loop when a reading a file | ricardo.ludwig | Shell Programming and Scripting | 4 | 05-23-2009 11:14 PM |
| split and making an array inside another array | dcfargo | Shell Programming and Scripting | 2 | 08-06-2008 10:07 AM |
| Access value outside awk or split value of array | jason.bean | UNIX for Dummies Questions & Answers | 1 | 11-26-2007 03:33 PM |
|
|