Sponsored Content
Top Forums Shell Programming and Scripting Construct Array from String seperated by different whitespaces Post 303038947 by mohtashims on Wednesday 18th of September 2019 05:45:14 AM
Old 09-18-2019
Construct Array from String seperated by different whitespaces

My string variable which gets the output from the result of a database query has values as below:

Code:
line="2019-09-11 15:17:55 CR1234 anonymous       Deployed        DR_only        Back_APP"

I wish to construct an array (my_array) which should have entries as below.

Quote:
my_array[0]=2019-09-11 15:17:55
my_array[1]=CR1234
my_array[2]=anonymous
my_array[3]=Deployed
my_array[4]=DR_only
my_array[5]=Back_APP
Note:
1. The first two strings seperated by whitespace combines to be the first element of the array.
2. Not all white spaces between the strings are the same.

Below code code does not split all the elements of the string as desired.

Code:
      IFS=$' ' read -ra my_array <<< "$line"
      #Print the split string
      for i in "${my_array[@]}"
      do
         echo $i
      done

Can you please propose a viable solution ?

I m on Redhat Linux centos 7 using bash.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To split a string to obtain the words delimited by whitespaces

Please can someone thow some light what is the best way to split a string to obtain the words delimited by whitespaces. (4 Replies)
Discussion started by: Sudhakar333
4 Replies

2. Shell Programming and Scripting

Removing blank lines from comma seperated and space seperated file.

Hi, I want to remove empty/blank lines from comma seperated and space seperated files Thanks all for help (11 Replies)
Discussion started by: pinnacle
11 Replies

3. Shell Programming and Scripting

construct a string with X number of spaces

I'd like to create a variable with the value of X number of space( no Perl please), printf seems to work, but , in following example,10 spaces becomes 1 space when assinged to a variable, Why? other solutions are welcome. $printf "=%10s=\n" = = $var=$(printf "=%10s=\n") echo... (4 Replies)
Discussion started by: honglus
4 Replies

4. Shell Programming and Scripting

Substring in string with whitespaces

hello, i have this string: variable="1234 /PARAMETER_1:text /PARAMETER_2:othertext" i tried to do expr match $variable '.*\(*\)' but i keep getting expr error i need to extract the word text... thank you (4 Replies)
Discussion started by: Aloush89
4 Replies

5. Shell Programming and Scripting

Convert comma seperated file to line seperated.

Hi, I have data like this. 1,2,3,4 Output required: 1 2 3 4 I am trying to use tr function but getting error. Help is appreciated. (6 Replies)
Discussion started by: pinnacle
6 Replies

6. Shell Programming and Scripting

PERL : Read an array and write to another array with intial string pattern checks

I have an array and two variables as below, I need to check if $datevar is present in $filename. If so, i need to replace $filename with the values in the array. I need the output inside an ARRAY How can this be done. Any help will be appreciated. Thanks in advance. (2 Replies)
Discussion started by: irudayaraj
2 Replies

7. Shell Programming and Scripting

For loop; how to construct a array with variables

Hi everybody!! Here is the thing; I have a trouble in this simple situation, I'm trying to write an array with all the arguments of a command. I mean, if I have: ./mycommand.sh aa bb cc dd I need to take an array like this: myarray=(aa bb cc dd) So I use a simple for loop like this: for... (4 Replies)
Discussion started by: andresgom
4 Replies

8. OS X (Apple)

Create a bash array from a flat file of whitespaces only.

Hi guys and gals... MacBook Pro. OSX 10.13.2, default bash terminal. I have a flat file 1920 bytes in size of whitespaces only. I need to put every single whitespace character into a bash array cell. Below are two methods that work, but both are seriously ugly. The first one requires that I... (7 Replies)
Discussion started by: wisecracker
7 Replies

9. Shell Programming and Scripting

Seperated a Column from 'ESC' Character seperated file

Hi Experts I have an escape seperated fields in the unix file. And in the below format file I need to extract the first column. Please help its urgent. cat -v op.dat | head 24397028^ I want to extract the file in below format ( with only first column ) 24397028 2439707 thanks. ... (6 Replies)
Discussion started by: neha_suri06
6 Replies

10. UNIX for Beginners Questions & Answers

awk Associative Array and/or Referring to Field by String (Nonconstant String Value)

I will start with an example of what I'm trying to do and then describe how I am approaching the issue. File PS028,005 Lexeme HRS # M # PhraseType 1(1:1) 7(7) PhraseLab 501 503 ClauseType ZYq0 PS028,005 Lexeme W # L> # BNH # M #... (17 Replies)
Discussion started by: jvoot
17 Replies
VASY(5) 						       VHDL subset of VASY.							   VASY(5)

NAME
vasy VHDL RTL subset. ORIGIN
This software belongs to the ALLIANCE CAD SYSTEM developed by the ASIM team at LIP6 laboratory of Universite Pierre et Marie CURIE, in Paris, France. Web : http://asim.lip6.fr/recherche/alliance/ E-mail : alliance-users@asim.lip6.fr DESCRIPTION
This document describes the VHDL subset accepted by VASY for RTL descriptions. CONCURRENT STATEMENTS In an RTL architecture most of the concurrent statements are supported. Allowed concurrent statements are: block concurrent assertion process concurrent signal assignment component instantiation statement generate statement SEQUENTIAL STATEMENTS Inside a process, all sequential statements including loops, signal assignment, variable assignment are supported. TYPE All types usefull for synthesis are accepted (IEEE-1164 and IEEE-1076.3), and all types defined in the VHDL Alliance subset (see vbe(5) for more details). OPERATORS All operators usefull for synthesis are accepted, such as arithmetic, logical and relationnal operators (IEEE-1164 and IEEE-1076.3), and those defined in the VHDL Alliance subset (see vbe(5) for more details). HARDWARE DESCRIPTION EXAMPLES A MULTIPLEXER may be described as follow: library IEEE; use IEEE.std_logic_1164.all; entity mux is port( sel,a,b : in std_logic; mux_out : out std_logic ); end mux; architecture rtl_1 of mux is begin process( sel,a,b ) begin if (sel='1') then mux_out <= a; else mux_out <= b; end if; end process; end rtl_1; architecture rtl_2 of mux is begin mux_out <= a when sel='1' else b; end rtl_2; A LATCH may be described as follow: library IEEE; use IEEE.std_logic_1164.all; entity latch is port( en,a : in std_logic; latch_out : out std_logic ); end latch; architecture rtl_1 of latch is begin process( en, a ) begin if (en='1') then latch_out <= a; end if; end process; end rtl_1; A D-FLIP-FLOP may be described as follow: library IEEE; use IEEE.std_logic_1164.all; entity d_ff is port( ck,a : in std_logic; d_ff_out : out std_logic ); end d_ff; architecture rtl_1 of d_ff is begin process( ck ) begin if (ck='1') then d_ff_out <= a; end if; end process; end rtl_1; architecture rtl_2 of d_ff is begin process( ck ) begin if (ck='1' and ck'event) then d_ff_out <= a; end if; end process; end rtl_2; architecture rtl_3 of d_ff is begin process begin wait until ck='1'; d_ff_out <= a; end process; end rtl_3; A TRISTATE BUFFER may be described as follow: library IEEE; use IEEE.std_logic_1164.all; entity trs is port( en,a : in std_logic; trs_out : out std_logic ); end trs; architecture rtl_1 of trs is begin process( en,a ) begin if (en='1') then trs_out <= a; else trs_out <= 'Z'; end if; end process; end rtl_1; architecture rtl_2 of d_ff is begin trs_out <= a when en='1' else 'Z'; end rtl_2; A RAM may be described as follow: library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity ram is port( clk,wr : in std_logic; adr : std_logic_vector(1 downto 0); i0 : in std_logic_vector(3 downto 0); o0 : out std_logic_vector(3 downto 0) ); end ram; architecture rtl_1 of ram is type my_array is array (0 to 3) of std_logic_vector(3 downto 0); signal s : my_array; begin process begin wait until (clk='0' and clk'event); if (wr='1') then s(to_integer(unsigned(adr))) <= I0; end if; end process; o0 <= s(to_integer(unsigned(adr))); end rtl_1; A ROM may be described as follow: library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity rom is port( adr : in std_logic_vector(1 downto 0); o0 : out std_logic_vector(3 downto 0) ); end rom; architecture rtl_1 of rom is subtype my_word is std_logic_vector(3 downto 0); type my_array is array (0 to 3) of my_word; constant s : my_array := ( "0000", "0001", "0010", "0011" ); begin o0 <= s(to_integer(unsigned(adr))); end rtl_1; A PRIORITY DECODER may be described as follow: library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity decod is port( A : in std_logic_vector(3 downto 0); B : out std_logic_vector(2 downto 0)); end decod; architecture rtl_1 of decod is begin process( a ) begin b <= "111"; for i in a'range -- Static For Loop are unrolled ! loop exit when a(i)='1'; b <= std_logic_vector(to_unsigned(i,3)); end loop; end process; end rtl_1; SEE ALSO
vasy(1), vbe(5), vhdl(5), vst(5), boom(1), loon(1), boog(1), asimut(1), proof(1) BUG REPORT
This tool is under development at the ASIM department of the LIP6 laboratory. We need your feedback to improve documentation and tools. ASIM
/LIP6 December 11, 1999 VASY(5)
All times are GMT -4. The time now is 12:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy