I have ASCII file and I want to output the file name and a specific field from this file beside each other. For example:
The contents of the ASCII file "data1.txt" is as follow:
Name: John
Age: 90
Gender: Male
Date: 20160105
I have a very long list of folders. Inside every folder I have the file data1.txt
. The files share the same design like how I showed before but the content is different.
In the parent folder I created I text file with the list of folders and I named it all.txt
. Then I wrote the following bash script:
#!/bin/bash
PAT=PATH TO THE PARENT FOLDER
for i in $(cat $PAT/all.txt); do
sed -n '/Name:/p' $PAT/$i/data1.txt | awk '{ print $2}'
How can I revise the previous code to print the following:
data1: John