what i want is to use gsub result later on, how could i achieve it?
Let say i have a "$j" variable coming from a for-do loop (its a directory) and im using this variable in nawk by assinging it to dir, but i want to use it first stripping "." at the beginning. something like the following but i know red highlighted "dir" does not do what i want:
Sorry? More context, please.
Some ad hoc comments:
Escape the dot wildcard char to really drop the leading "." only.
gsub on an anchored regex doesn't make sense (although it doesn't hurt); there's only one match.
Repeatedly applying gsub("^.","",dir) will eventually (= after a few lines) empty the dir variable.
Oki Let me provide you more detailed input so that it could give you a clue what im trying to do:
bash-3.00$ for j in $(find . -type d -name "`date +%Y%m%d`" 2>/dev/null);do echo $j ;done
./output/fail/20141127
./output/20141127
./abm/20141127
./so/20141127
./error/20141127
./error/suspension/20141127
./ccn/20141127
./input/20141127
There are several files under those folders above, and in those files there are several rows (records) too.
By using a one liner (otherwise i need complicated a scrpit file to write) I would like to print these daily created folders and their last 2 files under like this:
bash-3.00$ for j in $(find . -type d -name "`date +%Y%m%d`" 2>/dev/null);do echo -e "\n`pwd`${j#.}" && ls "`pwd`${j#.}" | tail -2;done
/data/sdp/omm/log/output/fail/20141127
/data/sdp/omm/log/output/20141127
000248outputparams_20141127111523.txt
000249outputparams_20141127111553.txt
/data/sdp/omm/log/abm/20141127
000029abm_20141127031628.txt
000030abm_20141127031638.txt
It could be very nice to print the context of each file next to the file name
context of those txt files are pipe seperated such as "a|b1|c3|4|55|x|y|z"