I'm trying to rename multiple files containing dates. I want to split the date into year, month and day and then create a new filename in a directory tree like year/month-year/filename_yearmonthday.extension
I already succeeded in creating a sed expression to filter out the date and write it back into three separate variables. I would now like to insert the values into an array, where [0] is year, [1] is month and [2] is day. I tried the following statement:
#!/bin/bash for i in * do myarray=( $(echo ${i} | \ sed -n 's/.*\([0-9]\{4\}\)\([0-9]\{2\}\)\([0-9]\{2\}\).*/\1 \2 \3/p' ) ) done
but the script complains about Syntax error: "(" unexpected (expecting "done") in the third line containing the sed-expression.
***edit The position of the date keeps changing, so I can't just split by strings.
As of now, I don't even succeed in something like this:
#!/bin/bash myarray=(1 2 3 4) echo ${myarray[@]}
it always tells me "Syntax error: "(" unexpected (expecting "done")" in the line containing the array. ***endedit
If I do this directly in the command line, it's working. Thanks for the help.
/bin/bash
if you want a bash script.. regarding syntax error, I think\3)/p' )
should be\3/p' ) )
.. there are other issues in your script as well, such as mywiki.wooledge.org/ParsingLsif..fi
portion of the script? if not, you will have to post the code inif..fi
as well