0
cd /var/opt/sw/e4/data/dev/e4_dev/DEVL3/EW/EWD1/DATA/AED/INPUT
for file in *;do tar -czf ../OUTPUT/"${file}".tar; done

According to the above code the files in input path eg. aedlog, aaalog... (file name) are placed in the output path as aedlog.tar, aaalog.tar... etc

How can i change the code such that the files are place in the output path with new name format EDWfile_01.tar, EDWfile_02.tar...etc ?

berndbausch
  • 1,033
  • 8
  • 12

1 Answers1

0

What about using a little programming? :-) Of course you can do it in one line using ; and yes, it's possible to do it more compact way, but the point is in understanding, isn't it?

cd /var/opt/sw/e4/data/dev/e4_dev/DEVL3/EW/EWD1/DATA/AED/INPUT
no=1 ; prefix="../OUTPUT/EDWfile_" ; suffix=".tar"
for file in * ; do
  filename=$(printf "%s%02d%s" $prefix $no $suffix)
  tar -czf $filename $file
  let $((no++))
done
d.c.
  • 257
  • 1
  • 2
  • 8
  • no++ getting error more tokens expected...can you help me with this? – Subramanian Feb 17 '21 at 05:14
  • Which OS, which shell? Well, you could use `no=$((no+1))` but probably it's just a typo. Tried using clipboard on bash on OS X and OpenBSD with ksh. On dash the second variant is needed but the error is different (and it's rather annoying shell to work with). – d.c. Feb 17 '21 at 11:05