reading a .dat file in to a string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting reading a .dat file in to a string
# 8  
Old 04-23-2010
Try:
Code:
name="$name
$new_variable"

# 9  
Old 04-23-2010
i have following Kshell code. It is working almost perfect. Only issue is, when it writes in to the array, it start with location 1, instead of location 0. for example it will load the array as follows,
ignore[0]=
ignore[1]=wefwf12
ignore[2]=23dfjrtgt
.
.
ignore[n]=erfe3445

How do i get this issue fixed?

Code:
for i in $(grep -v "#" ../data/globallyIgnoredTc.dat | awk !/^$/ | awk -F" " '{print NR}' )
do
#echo i =$i
nam_arr[$i]=$(grep -v "#" ../data/globallyIgnoredTc.dat | awk !/^$/ | awk -F " " -v cnter=$i '{if (cnter == NR){print $1}}')
done

i=0
while [[ $i -lt ${#nam_arr[*]} ]] ; do
echo " nam_arr[$i] = ${nam_arr[$i]}"
let i=$i+1
done

# 10  
Old 04-23-2010
Without reading too much into the rest of the code, I would say:

Code:
for i in $(grep -v "#" ../data/globallyIgnoredTc.dat | awk !/^$/ | awk -F" " '{print NR-1}' )

# 11  
Old 04-23-2010
Acctually, it didnt do any difference.


my data fine looks like this,
#gfbdnjbdn rfgrfgr
#
#vdfdg erergerg

srgr345 VVDRG56F
455jgg DFERTGvF
.
.
rgbb45 SDFVDDGGB
# 12  
Old 04-23-2010
Odd Smilie

Code:
$ cat MyTest
echo Original
grep -v "#" file1 | awk '!/^$/' | awk -F" " '{print NR}'
echo
echo New
grep -v "#" file1 | awk '!/^$/' | awk -F" " '{print NR-1}'
echo
echo For Loop
for i in $(grep -v "#" file1 | awk '!/^$/' | awk -F" " '{print NR - 1}' ); do
  echo $i
done

$ cat file1
#gfbdnjbdn rfgrfgr
#
#vdfdg erergerg

srgr345 VVDRG56F
455jgg DFERTGvF
.
.
rgbb45 SDFVDDGGB


$ ./MyTest
Original
1
2
3
4
5

New
0
1
2
3
4

For Loop
0
1
2
3
4

# 13  
Old 04-23-2010
it is odd. if i send u the data file, do u have a second to run this?
# 14  
Old 04-23-2010
Quote:
Originally Posted by usustarr
it is odd. if i send u the data file, do u have a second to run this?
Sure. Send it over (your script too - if not the same as above)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to use 'ls' command to list files like *.dat, not *.*.dat?

How to use 'ls' command to list files like *.dat, not *.*.dat (5 Replies)
Discussion started by: pmcginni777
5 Replies

2. Shell Programming and Scripting

Execution of loop :Splitting a single file into multiple .dat file

hdr=$(cut -c1 $path$file|head -1)#extract header”H” trl=$(cut -c|path$file|tail -1)#extract trailer “T” SplitFile=$(cut -c 50-250 $path 1$newfile |sed'$/ *$//' head -1')# to trim white space and extract table name If; then # start loop if it is a header While read I #read file Do... (4 Replies)
Discussion started by: SwagatikaP1
4 Replies

3. Shell Programming and Scripting

FASTEN count line of dat file and compare with the CTRL file

Hi All, I thinking on how to accelerate the speed on calculate the dat file against the number of records CTRL file. There are about 300 to 400 folder directories that contains both DAT and CTL files. DAT contain all the flat files records CTL is the reference check file for the... (3 Replies)
Discussion started by: ckwan
3 Replies

4. UNIX for Dummies Questions & Answers

ID incorrect field values in dat file and output to new file

Hi All I have a .dat file, the values are seperated by ". I wish to identify all field values in field 14 that are not '01-APR-2013' band then copy those records to a new file. Can anyone suggest the UNIX command required. Thanks in advance Andy (2 Replies)
Discussion started by: aurum1313
2 Replies

5. Shell Programming and Scripting

File Reading for a certain string and echo the line before

Hi Guys, I have a big file like this. It has cache group line ( the bold lines ) and then followed by 10 status lines showing either Compelte or Failed. This pattern repeats several time. We can assume all the status lines have either Complete or Failed status for that Cache Group line. I... (13 Replies)
Discussion started by: MKNENI
13 Replies

6. Shell Programming and Scripting

Reading a .dat file in to 2 different arrays

hi all, i have a data file that contains 2 columns, names and numbers. i need to read names in to a an array call names and numbers in to an array call numbers. i also have # and blank lines in my dat file and i need to skip those when i read the dat file. how do i do this? btw, my column 1 and... (3 Replies)
Discussion started by: usustarr
3 Replies

7. Shell Programming and Scripting

Performance issue in UNIX while generating .dat file from large text file

Hello Gurus, We are facing some performance issue in UNIX. If someone had faced such kind of issue in past please provide your suggestions on this . Problem Definition: /Few of load processes of our Finance Application are facing issue in UNIX when they uses a shell script having below... (19 Replies)
Discussion started by: KRAMA
19 Replies

8. UNIX for Dummies Questions & Answers

How do I delete a data string from a .dat file in unix

I have a .dat file in unix and it keeps failing file validation on line x. How do I delete a data string from a .dat file in UNIX? I tried the following: sed -e 'data string' -e file name and it telling me unrecognized command (4 Replies)
Discussion started by: supergirl3954
4 Replies

9. Shell Programming and Scripting

How to attach an excel file/ dat file thru unix mails

Hi. I want to attach a .xls or .dat file while sending mail thru unix. I have come across diff attachments sending options, but allthose embeds the content in the mail. I want the attachement to be send as such. Please help me out. regards Diwakar (1 Reply)
Discussion started by: diwakar82
1 Replies

10. UNIX for Dummies Questions & Answers

Reading and writing SCO DAT tapes uing Linux

Hi, Guys. I've been trying to read and write SCO DAT tapes to my Linux hard disk. I'm using RedHat 6.0 because it is the only version that has device drivers for my SCSI host adapter and SCSI tape drive. When I run the command "cpio -ivt > /dev/st0" I can read the archive from the SCO... (3 Replies)
Discussion started by: cstovall
3 Replies
Login or Register to Ask a Question