Sponsored Content
Top Forums Shell Programming and Scripting Read character and use as separator Post 302943218 by Subbeh on Wednesday 6th of May 2015 11:08:21 AM
Old 05-06-2015
Read character and use as separator

Hi all,

I'm trying to read in a character and use it as a separater on a string:

Code:
#!/bin/ksh

echo "Enter input line"
read input_header

echo "Enter separator:"
read separator

IFS="$separator" read -A fields <<< "$input_header"

for ((i=0;i<${#fields[@]};i++)) ; do
  echo ${fields[$i]}
done

This works when using characters like comma's etc. But not with spaces and tabs:

Code:
-bash-4.1$ ./test.ksh
Enter input line
test1,test2,test3
Enter separator:
,
test1
test2
test3
-bash-4.1$ ./test.ksh
Enter input line
test1 test2 test3
Enter separator:
   <- space
test1 test2 test3

Is there any way to do this?

Thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can i read a file character by character

How to read character by character using awk (6 Replies)
Discussion started by: karnan
6 Replies

2. UNIX for Dummies Questions & Answers

read a variable character by character, substitute characters with something else

im having trouble doing this: i have a variable with 2 characters repeating e.g. aababbbaaaababaabbaabbba is there a way i can search the variable for a's and b's and then change a's to b's and b's to a's? im guessing its like getting the 1's compliment of the string im doing this in... (2 Replies)
Discussion started by: vipervenom25
2 Replies

3. Shell Programming and Scripting

read in a file character by character - replace any unknown ASCII characters with spa

Can someone help me to write a script / command to read in a file, character by character, replace any unknown ASCII characters with space. then write out the file to a new filename/ Thanks! (1 Reply)
Discussion started by: raghav525
1 Replies

4. Shell Programming and Scripting

Can I read a file character by character?

Hello all respected people, Can i read a file character by character without using sed,awk and perl commands. Thanks in advance. (4 Replies)
Discussion started by: murtaza
4 Replies

5. Shell Programming and Scripting

How to read character by character in a file

Hi, How read character by character from a file . and i need replace '.' with null if it comes as a 5 character i am beginner ...please help me (1 Reply)
Discussion started by: kartheek
1 Replies

6. UNIX for Dummies Questions & Answers

read from character 23 through character 32

I need a one-liner that will output characters 23 through 32 from a user defined record. Thanks, Kenny. (1 Reply)
Discussion started by: kenneth.mcbride
1 Replies

7. Shell Programming and Scripting

read the text file and print the content character by character..

hello all i request you to give the solution for the following problem.. I want read the text file.and print the contents character by character..like if the text file contains google means..i want to print g go goo goog googl google like this Using unix Shell scripting... without using... (1 Reply)
Discussion started by: samupnl
1 Replies

8. Shell Programming and Scripting

Read character by character

Guys, Here is the input text file <7001> 34 789 701 2 <HJS1> 2 <HJS2> 2 <HJS3> ... (2 Replies)
Discussion started by: gowrishankar05
2 Replies

9. Shell Programming and Scripting

read into a range of character

i have this problem: i must hide a string with a character such as _ by command WORD=string; XXX=`echo $WORD | sed 's//_/g' but after, users must send in input a character and i must to replace the _ with the input character or better i can do this -$CHARS_INPUT i have think to use command... (3 Replies)
Discussion started by: tafazzi87
3 Replies

10. Shell Programming and Scripting

Read character by character in line in which space is also included

Hi friend, I have one file , and i want to read that file character by character. I need this script in ksh. while using read option with -n1 am getting error. while read -n1 c read has bad option And if i am using below script, then if in a line has space like this ( Pallvi mahajan)... (10 Replies)
Discussion started by: pallvi_mahajan
10 Replies
CARTCONVERT(1)						      GeographicLib Utilities						    CARTCONVERT(1)

NAME
CartConvert -- convert geodetic coordinates to geocentric or local cartesian SYNOPSIS
CartConvert [ -r ] [ -l lat0 lon0 h0 ] [ -e a f ] [ --comment-delimiter commentdelim ] [ --version | -h | --help ] [ --input-file infile | --input-string instring ] [ --line-separator linesep ] [ --output-file outfile ] DESCRIPTION
Convert geodetic coordinates to either geocentric or local cartesian coordinates. Geocentric coordinates have the origin at the center of the earth, with the z axis going thru the north pole, and the x axis thru latitude = 0, longitude = 0. By default, the conversion is to geocentric coordinates. Specifying -l lat0 lon0 h0 causes a local coordinate system to be used with the origin at latitude = lat0, longitude = lon0, height = h0, z normal to the ellipsoid and y due north. Geodetic coordinates are provided on standard input as a set of lines containing (blank separated) latitude, longitude (decimal degrees or degrees, minutes and seconds), and height above the ellipsoid (meters). For each set of geodetic coordinates, the corresponding cartesian coordinates x, y, z (meters) are printed on standard output. OPTIONS
-r perform the reverse projection. x, y, z are given on standard input and each line of standard output gives latitude, longitude, height. -e specify the ellipsoid via a f; the equatorial radius is a and the flattening is f. Setting f = 0 results in a sphere. Specify f < 0 for a prolate ellipsoid. A simple fraction, e.g., 1/297, is allowed for f. (Also, if f > 1, the flattening is set to 1/f.) By default, the WGS84 ellipsoid is used, a = 6378137 m, f = 1/298.257223563. --comment-delimiter set the comment delimiter to commentdelim (e.g., "#" or "//"). If set, the input lines will be scanned for this delimiter and, if found, the delimiter and the rest of the line will be removed prior to processing and subsequently appended to the output line (separated by a space). --version print version and exit. -h print usage and exit. --help print full documentation and exit. --input-file read input from the file infile instead of from standard input; a file name of "-" stands for standard input. --input-string read input from the string instring instead of from standard input. All occurrences of the line separator character (default is a semicolon) in instring are converted to newlines before the reading begins. --line-separator set the line separator character to linesep. By default this is a semicolon. --output-file write output to the file outfile instead of to standard output; a file name of "-" stands for standard output. EXAMPLES
echo 33.3 44.4 6000 | CartConvert => 3816209.60 3737108.55 3485109.57 echo 33.3 44.4 6000 | CartConvert -l 33 44 20 => 37288.97 33374.29 5783.64 echo 30000 30000 0 | CartConvert -r => 6.483 45 -6335709.73 ERRORS
An illegal line of input will print an error message to standard output beginning with "ERROR:" and causes CartConvert to return an exit code of 1. However, an error does not cause CartConvert to terminate; following lines will be converted. SEE ALSO
The algorithm for converting geocentric to geodetic coordinates is given in Appendix B of C. F. F. Karney, Geodesics on an ellipsoid of revolution, Feb. 2011; preprint <http://arxiv.org/abs/1102.1215>. AUTHOR
CartConvert was written by Charles Karney. HISTORY
CartConvert was added to GeographicLib, <http://geographiclib.sf.net>, in 2009-02. Prior to 2009-03 it was called ECEFConvert. GeographicLib 1.21 2012-04-24 CARTCONVERT(1)
All times are GMT -4. The time now is 07:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy