Well, you generated a series of fantastic data by varying some parameter, which was used to name your data file. Now you need to process these data again but then realize that you didn't save the values of this parameter. What can you do? I hope that you are not thinking of copying every single value in the file names!
Here is how you can do it using awk in two lines. Say the file names are in the following format: "xxxxx_1.553_fsolve.mat." First you save all the file names as a txt file:
ls *fsolve.mat > namelist
Then do the following:
cat namelist | awk '{split($0, a, "_"); print a[2]}' > namelist2
$0 is the stdout from "cat namelist"; "a" is a string array generated from $0 with the delimiter "_", and in our case it has three elements: a[1]="xxxxx", a[2]="1.553", and a[3]=".mat". What remains to finish the task is to print a[2] to a file ("namelist2").
To better understand the use of split, we can accomplish the above using one more split command
cat namelist | awk '{split($0, a, "_fsolve"); split(a[1],b,"_"); print b[2]}' > namelist2
See how it works :)
No comments:
Post a Comment