Bash -

Pagina: 1
Acties:
  • 253 views

Acties:
  • 0 Henk 'm!

  • xirixiz
  • Registratie: Juli 2009
  • Laatst online: 15-09 19:44
Hey,

I'm trying to create a bash script to do the following;

example source files:
- a_b_c_qwer_e_123.xml
- a_b_c_rewq_e_abc.xml
- a_b_c_tyui_e_cba.xml
- a_b_c_iuyt_e_321.xml
- a_b_c_qazws_e_000.xml
- a_b_c_swzaq_e_333.xml

What i would like to do is extract the first part of a filename.

For example "a_b_c_qwer_e_123.xml" is the filename, what I need to extract is this part: "a_b_c_qwer_e" without the source filnames being renamed.

Then the following needs to be done. Based on the first part of the file, in this case "a_b_c_qwer_e", the file has to be copied to the directory "/a_b_c_qwer_e". So actually it's a (partly)filename based copy.

What I've created so far is the following...which sux due to I`m creating a lot of variables this way.
I searched on google but couldn't find a good result. Hope someone can help me out! Tx!


#!/bin/bash

QUEUE_01="a_b_c_qwer_e"
QUEUE_02="a_b_c_rewq_e"
QUEUE_03="a_b_c_tyui_e"
QUEUE_04="a_b_c_iuyt_e"
QUEUE_05="a_b_c_qazws_e"
QUEUE_06="a_b_c_swzaq_e"

ls -1 | while read file
do
cp $file $(echo $file | cut -f1 -d"_" ).$(echo $file | cut -f2 -d".")
done

Also known as xirixiz


Acties:
  • 0 Henk 'm!

  • Emmeau
  • Registratie: Mei 2003
  • Niet online

Emmeau

All your UNIX are belong to us

dit is typisch iets voor sed

regexp bouwen die doet wat je wilt, en de bestandsnamen er doorheen halen.

Succes
En je post mag/moet gewoon in het nederlands :)

[ Voor 21% gewijzigd door Emmeau op 23-11-2009 15:42 ]

If you choose to criticise you choose your enemies


Acties:
  • 0 Henk 'm!

  • RobIII
  • Registratie: December 2001
  • Niet online

RobIII

Admin Devschuur®

^ Romeinse Ⅲ ja!

(overleden)
We speaken Dutch hier op tweakers.net ;) :+
Open gerust een nieuw topic, maar kijk dan even in Waar hoort mijn topic? en onze Quickstart ;)

There are only two hard problems in distributed systems: 2. Exactly-once delivery 1. Guaranteed order of messages 2. Exactly-once delivery.

Je eigen tweaker.me redirect

Over mij


Dit topic is gesloten.