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
# 1  
Old 04-22-2010
reading a .dat file in to a string

i have folowing code.

i dont want data in an array. i like to put my data file info (after filtering and converting to lower case) in to a string call "name". so it would look like this,

name= ffjtgj345 thgkty3 456gfhf rhtfn4 ......
how do i do that? i dont want to read # or blank lines.

my data file look like this,

ffjtgj345
thgkty3
456gfhf

rhtfn4
#rfrgdbg
3434df

Last edited by usustarr; 05-28-2010 at 07:18 PM..
# 2  
Old 04-22-2010
Code:
file=../data/globallyIgnoredTc.dat
name=$(echo $(awk '!/#/{print tolower}' $file1))

# 3  
Old 04-22-2010
Hi Scottn, why the echo?
Code:
name=$(awk '!/^#/&&NF{printf tolower($0" ")}' ../data/globallyIgnoredTc.dat)

Code:
$ echo "$name"
ffjtgj345 thgkty3 456gfhf rhtfn4 3434df

- or -
Code:
name=$(awk '!/^#/&&NF{print tolower($0)}' ../data/globallyIgnoredTc.dat)

- or -
Code:
name=$(egrep -v "^#|^$" ../data/globallyIgnoredTc.dat | tr [:upper:] [:lower:] )

Code:
$ echo $name
ffjtgj345 thgkty3 456gfhf rhtfn4 3434df

$ echo "$name"
ffjtgj345
thgkty3
456gfhf
rhtfn4
3434df


Last edited by Scrutinizer; 04-22-2010 at 04:52 PM..
# 4  
Old 04-22-2010
The echo was a lazy way of removing blank lines and carriage return when quoting $name, as you did with your first awk
# 5  
Old 04-22-2010
Thanks guys, i will try that.
# 6  
Old 04-22-2010
Quote:
Originally Posted by scottn
The echo was a lazy way of removing blank lines and carriage return when quoting $name, as you did with your first awk
Smilie I know, I just realized.. I think I'll go to bed early tonight Smilie
# 7  
Old 04-22-2010
i am tring to add values in to my original string. i was doing

Code:
name="$name  $new_variable"

but that cause me to print my string as follows,
name=
wfhugh344
djfv343444
.
.
.
uferjt23 <new_variable>

how do i get this new Variable add in to my string so that it will print as follows,


name=
wfhugh344
djfv343444
.
.
.
uferjt23
<new_variable>
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