1

Let l have a file that contain a data like this:

-ab-a--a-- 1 abcd   abcd        934M Nov  2 00:14 abc_de-123.456.xyz-2022-11-02_1234567890.zip
-ab-a--a-- 1 abcd   abcd         45M Nov  2 01:39 abc_de-123.456.xyz-2022-11-02_1234567890.zip
-ab-a--a-- 1 abcd   abcd        7.1G Nov 12 02:35 abc_de-123.456.xyz-2022-11-12_1234567890.zip
-ab-a--a-- 1 abcd   abcd       1020M Nov  9 03:32 abc_de-123.456.xyz-2022-11-09_1234567890.zip
-ab-a--a-- 1 abcd   abcd        1.1G Nov 12 04:32 abc_de-123.456.xyz-2022-11-12_1234567890.zip
-ab-a--a-- 1 abcd   abcd       1010G Nov  7 05:35 abc_de-123.456.xyz-2022-11-07_1234567890.zip
-ab-a--a-- 1 abcd   abcd        2.0G Nov 12 06:41 abc_de-123.456.xyz-2022-11-12_1234567890.zip

So how to store the time and zip file name in array from this file? There is different number of space in some rows.

I have tried this code:

readarray -t time_array <<< "cut -d ' ' -f  9 filename)"
readarray -t zip_array  <<< "cut -d ' ' -f 10 filename)"

this code only works when there is equal number of < space > as a column separator but in the file there is not same number of space as a column seperator

I want the the output as:

time array contains:

00:14 
01:39 
02:35 
03:32 
04:32 
05:35 
06:41 

and

zip_array contains:

abc_de-123.456.xyz-2022-11-02_1234567890.zip
abc_de-123.456.xyz-2022-11-02_1234567890.zip
abc_de-123.456.xyz-2022-11-12_1234567890.zip
abc_de-123.456.xyz-2022-11-09_1234567890.zip
abc_de-123.456.xyz-2022-11-12_1234567890.zip
abc_de-123.456.xyz-2022-11-07_1234567890.zip
abc_de-123.456.xyz-2022-11-12_1234567890.zip
5
  • If you do not insist to have the data in array you can use awk where you can further manage the data Commented Dec 28, 2022 at 9:38
  • Is it the output of ls -l ? If so, don't parse ls output. Commented Dec 28, 2022 at 10:09
  • 1
    DO NOT USE ls' output for anything. ls is a tool for interactively looking at directory metadata. Any attempts at parsing ls' output with code are broken. Globs are much more simple AND correct: ''for file in *.txt''. Read mywiki.wooledge.org/ParsingLs Commented Dec 28, 2022 at 10:10
  • 1
    Moreover, you have duplicate filenames Commented Dec 28, 2022 at 10:13
  • file permissions invalid -ab-a--a-- Commented Dec 28, 2022 at 15:01

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.