Ask Your Question

how to use fedora bash

asked 2017-02-06 09:23:09 -0600

erop gravatar image

updated 2017-02-06 13:06:02 -0600

florian gravatar image

examples input file names are ss-771AT.txt, ss-885BT.txt and ss-994_T.txt

my script is as follows

for fil in $( ls ss*_T.txt ) ; do


 echo ${id}

  if   [ ${id} = ~m/A/ ] ; then 

             $dir = "A" ;
             $che = 1 ;

  elif [ ${id} = ~m/B/ ] ; then 
             $dir = "B" ;
             $che = 2 ;


  echo " Check id " ${id}



  awk '{printf("%13.2f%13.2f%13.2f%13.2f\n",$1,$2,$3,$4)}' ${fil} > ${outT}


output is ss-885Brem.txt; ss-771rem.tx and ss-994rem.txt desired file ouputs are 7711rem.txt, 8852rem.txt and 994rem.txt

please kindly assist me to fix this error.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2017-02-07 18:38:02 -0600

ssieb gravatar image

This isn't a Fedora question, it's a general Bash question and should be asked elsewhere.

Anyway, there are two easier solutions.

  1. if [ ${id: -1} == "A" ]

  2. case "$id" in
      *A) A stuff;;
      *B) B stuff;;
      *) failed;;

You also don't remove the letter or the prefix from the id before creating the new name, so you probably want outT=${id:3:-1}${che}_rem.txt.

edit flag offensive delete link more

answered 2017-02-06 11:56:06 -0600

lsatenstein gravatar image

Should there not be a / between ~m/A as ~/m....

edit flag offensive delete link more


thank you Isatenstein; i cannot still get the desired output. the problem is the if statement i get the else output which is check id though have an A and B in the filename. The target of if statement is to replace A with 1 and B with 2 in the file output name for example for file input ss-771AT.txt i get ss-771A _rem.txt instead of 7711rem.txt.

erop gravatar imageerop ( 2017-02-06 20:03:29 -0600 )edit

Question Tools

1 follower


Asked: 2017-02-06 09:23:09 -0600

Seen: 172 times

Last updated: Feb 07 '17