Issue with reading in records


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Issue with reading in records
# 1  
Old 08-11-2006
Issue with reading in records

Hi all,

This is my first post here, so please bear with me!

I have a file coming into a korn shell script, fixed length. Example:

Peter (25 spaces) D (29 spaces) Younan (24 spaces)
Jim (27 spaces) (30 spaces) Shue (26 spaces)

I am performing a while loop to read in the file and assign each record to a variable called THELINE. I then try to assign the various columns by doing an echo and piping into cut. Example:
FIELD1=`echo $THELINE | cut -c1-15` # FIRST NAME
FIELD2=`echo $THELINE | cut -c16-45` # MIDDLE NAME
etc

What's happening is echo is compressing the "extra" white spaces between the name fields, so FIELD1 looks like this:
Peter D Younan
instead of this (desired):
Peter


Any ideas on how I can get around this issue?

Thanks!
Pete
# 2  
Old 08-11-2006
Try :
Code:
FIELD1="`echo $THELINE | cut -c1-15`" # FIRST NAME
FIELD2="`echo $THELINE | cut -c16-45`" # MIDDLE NAME


Jean-Pierre.
# 3  
Old 08-11-2006
Thanks J.P!
# 4  
Old 08-14-2006
Whenever you want to retain extra spaces use "". like echo "$theline".

FIELD1=`echo "$THELINE" | cut -c1-15` # FIRST NAME
FIELD2=`echo "$THELINE" | cut -c16-45` # MIDDLE NAME
# 5  
Old 08-14-2006
Thanks!

Thank you both very much. This helped me considerably!
Pete
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

1. This will insert the records into db table by reading from ta csv file

I have this code with me but the condition is If any of the mandatory columns are null then entire file will be rejected. LOAD DATA infile ' ' #specifies the name of a datafile containing data that you want to load BADFILE ' ' #specifies the name of... (1 Reply)
Discussion started by: raka123
1 Replies

2. Shell Programming and Scripting

Issue catching/reading 2 digits and 3 letter string between brackets

Hello I'm writing a handler for ffmpeg, and having troubles to catch some exceptions that may occour with certain files. In order to parse for video & subtitle maps, i've had to make the raw data easier to handle, until now this worked well, but basicly i've just been lucky... The input... (1 Reply)
Discussion started by: sea
1 Replies

3. Shell Programming and Scripting

awk issue while reading from file in while do

Hi Friends, I am trying to scan line by line using awk and pull the values and pass it in variables and then will use the variables but doesn't work. Please see below for details. #more dbtest.sh ---------------------------------- #!/bin/bash . $HOME/.bash_profile while read line do... (6 Replies)
Discussion started by: narunice
6 Replies

4. Shell Programming and Scripting

Compare two files with different number of records and output only the Extra records from file1

Hi Freinds , I have 2 files . File 1 |nag|HYd|1|Che |esw|Gun|2|hyd |pra|bhe|3|hyd |omu|hei|4|bnsj |uer|oeri|5|uery File 2 |nag|HYd|1|Che |esw|Gun|2|hyd |uer|oi|3|uery output : (9 Replies)
Discussion started by: i150371485
9 Replies

5. Shell Programming and Scripting

Parsing issue while reading excel having 3000 record

Hi Need urgent help (2 Replies)
Discussion started by: premp26
2 Replies

6. UNIX for Dummies Questions & Answers

Grep specific records from a file of records that are separated by an empty line

Hi everyone. I am a newbie to Linux stuff. I have this kind of problem which couldn't solve alone. I have a text file with records separated by empty lines like this: ID: 20 Name: X Age: 19 ID: 21 Name: Z ID: 22 Email: xxx@yahoo.com Name: Y Age: 19 I want to grep records that... (4 Replies)
Discussion started by: Atrisa
4 Replies

7. UNIX for Dummies Questions & Answers

issue on reading the file and appending date

Hi Am having issue on appending time stamp I know the exact file names in the directory like a.dat b.dat c.dat e.dat f.dat I want to read all these file names and append the timestamp to each files like a.dat.20090604,b.dat.20090604 and move to the different directory. ... (3 Replies)
Discussion started by: bobprabhu
3 Replies

8. UNIX for Advanced & Expert Users

Issue reading csv file

HI All I have csv file containing the data like this Electrical Equipment,ElecEquip "Engineering, Machinery & Equipment",Engineerin Entertainment & Broadcasting,Entertain The first and third record are fine,The issue with second records as it has comma enclosed with in inverted... (1 Reply)
Discussion started by: mohdtausifsh
1 Replies

9. Shell Programming and Scripting

Based on num of records in file1 need to check records in file2 to set some condns

Hi All, I have two files say file1 and file2. I want to check the number of records in file1 and if its atleast 2 (i.e., 2 or greater than 2 ) then I have to check records in file2 .If records in file2 is atleast 1 (i.e. if its not empty ) i have to set some conditions . Could you pls... (3 Replies)
Discussion started by: mavesum
3 Replies

10. Shell Programming and Scripting

reading specifiec records from a file!!

I want to read all numeric records that start with the line id and write them to a new file. input: ==== blah blah blah blah id 10 11 12 13 14 15 blah blah blah blah id 16 17 18 19 20 21 output: 10 11 12 13 14 15 (10 Replies)
Discussion started by: andy2000
10 Replies
Login or Register to Ask a Question